<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vikas on Medium]]></title>
        <description><![CDATA[Stories by Vikas on Medium]]></description>
        <link>https://medium.com/@venkatavikasc?source=rss-f38265f53b7e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*P7XUEJDpXQ53AvDn5HfD2w.jpeg</url>
            <title>Stories by Vikas on Medium</title>
            <link>https://medium.com/@venkatavikasc?source=rss-f38265f53b7e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 06:40:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@venkatavikasc/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Make Dataverse Web API Calls Sequentially in Dynamics 365]]></title>
            <link>https://medium.com/@venkatavikasc/how-to-handle-web-api-call-sequentially-in-dynamics-365-ccf4723f1ed7?source=rss-f38265f53b7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccf4723f1ed7</guid>
            <category><![CDATA[async-or-await]]></category>
            <category><![CDATA[api-client]]></category>
            <category><![CDATA[call-webapi]]></category>
            <category><![CDATA[synchronous]]></category>
            <category><![CDATA[asynchronous]]></category>
            <dc:creator><![CDATA[Vikas]]></dc:creator>
            <pubDate>Mon, 09 Nov 2026 12:40:42 GMT</pubDate>
            <atom:updated>2026-11-17T10:24:21.974Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Fg_ln7IVxON9qNcg" /><figcaption>Photo by <a href="https://unsplash.com/@thekamranzadeh?utm_source=medium&amp;utm_medium=referral">Kamran Abdullayev</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In Dynamics 365, Dataverse Web API calls run asynchronously and return promises. To handle asynchronous responses in a sequential and readable way, you can use <strong><em>Async/Await</em></strong> or <strong><em>Promise</em> </strong>chaining<strong> </strong>(.then()).</p><p>Using <strong><em>async/await</em></strong>, execution within the async function pauses at the <strong><em>await </em></strong>statement until the asynchronous operation completes. This makes the code behave like synchronous code while keeping the UI responsive.</p><p>Let’s quickly look at the difference between <strong>Asynchronous</strong>&amp; <strong>Synchronous</strong> execution in JavaScript.</p><h4><strong>Asynchronous</strong></h4><ul><li>When a function is called, JavaScript does not wait for the operation to complete before continuing with the next statement.</li><li>Once the operation completes, the result is processed.</li><li>The completion order may differ from the order in which the functions were called.</li></ul><pre>//Functions are may executed in a non-sequence order.<br>console.log(&quot;First Line&quot;);<br>setTimeout(function (){ console.log(&quot;Second Line&quot;); }, 1000);<br>console.log(&quot;Third Line&quot;);<br><br>//Output<br>First Line<br>Third Line<br>Second Line </pre><ul><li>Best for Web API calls, External Integrations, Long-running operations.</li></ul><h4><strong>Synchronous</strong></h4><ul><li>JavaScript waits for the current operation to complete before executing the next statement.</li><li>Functions execute sequentially, one after another.</li></ul><pre>//Functions are executed in a sequential order.<br>console.log(&quot;First Line&quot;);<br>console.log(&quot;Second Line&quot;); <br>console.log(&quot;Third Line&quot;);<br><br>//Output<br>First Line<br>Second Line<br>Third Line</pre><ul><li>Best for Field validations, Operations that must complete before proceeding to the next step.</li></ul><h4>Scenario:</h4><p><em>Retrieve Paid Invoices and Calculate the Total amount paid by a candidate for courses taken without using a Rollup field in D365 using JS async/await.</em></p><pre>async function CalculateTotalAmountPaidByCandidate(formContext) {<br>    let candidateId = formContext.data.entity.getId().slice(1, -1);<br>    if (candidateId != null) {<br>        let query = &quot;&lt;fetch aggregate=&#39;true&#39;&gt;&quot;+<br>            &quot;&lt;entity name=&#39;new_invoice&#39;&gt;&quot;+<br>                &quot;&lt;attribute name=&#39;new_amount&#39; alias=&#39;amt&#39; aggregate=&#39;sum&#39; /&gt;&quot;+<br>                &quot;&lt;filter&gt;&quot;+<br>                    &quot;&lt;condition attribute=&#39;new_candidateid&#39; operator=&#39;eq&#39; value=&#39;&quot; + candidateId +&quot;&#39; uitype=&#39;new_candidate&#39; /&gt;&quot;+<br>                    &quot;&lt;condition attribute=&#39;statuscode&#39; operator=&#39;eq&#39; value=&#39;766100000&#39; /&gt;&quot;+<br>                &quot;&lt;/filter&gt;&quot;+<br>            &quot;&lt;/entity&gt;&quot;+<br>        &quot;&lt;/fetch&gt;&quot;;<br><br>        let encodedQuery = &quot;?fetchXml=&quot; + encodeURIComponent(query);<br>        let result = await Xrm.WebApi.retrieveMultipleRecords(&quot;new_invoice&quot;, encodedQuery);<br>        if (result != null &amp;&amp; result.entities.length == 1) {<br>            let record = result.entities[0];<br>            console.log(&quot;Total Amount Paid: &quot; + record[&quot;amt&quot;]);                <br>        }<br>    }<br>}</pre><h4>Code Explanation</h4><ul><li>Create a FetchXML query that retrieves all paid invoices for a specific candidate by dynamically passing the Candidate GUID.</li><li>Apply an aggregate sum on the Amount field and pass the encoded FetchXML to Xrm.WebApi.retrieveMultipleRecords().</li><li>The query returns a single record containing the total amount in the specified alias field.</li></ul><blockquote><strong>Note:</strong> Dataverse Web API calls are asynchronous and can be handled using success and error callback functions. Check <a href="https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi/retrievemultiplerecords">here</a>.</blockquote><p>Thanks for Reading.</p><p>Hope it helps you!!!</p><p><strong>Wait a moment. </strong>If you enjoyed this article, <strong><em>subscribe</em> </strong>to receive my latest articles directly in your inbox. Share it with your friends or colleagues who may find it helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccf4723f1ed7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Restrict BPF Stage Navigation in Dynamics 365]]></title>
            <link>https://medium.com/@venkatavikasc/prevent-users-from-navigating-back-to-a-previous-business-process-flow-bpf-stage-in-dynamics-365-c5a75ea0b539?source=rss-f38265f53b7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5a75ea0b539</guid>
            <category><![CDATA[bpf-stage]]></category>
            <category><![CDATA[business-process-flow]]></category>
            <category><![CDATA[api-client]]></category>
            <category><![CDATA[restrict-bpf]]></category>
            <category><![CDATA[microsoft-dynamics-365]]></category>
            <dc:creator><![CDATA[Vikas]]></dc:creator>
            <pubDate>Sun, 18 Oct 2026 07:49:47 GMT</pubDate>
            <atom:updated>2026-11-17T10:28:40.083Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SN7r4-D5NFkD5wfJ" /><figcaption>Photo by <a href="https://unsplash.com/@silverkblack?utm_source=medium&amp;utm_medium=referral">Vitaly Gariev</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In Dynamics 365 Client API, there are two Business Process Flow (BPF) stage change events:</p><ul><li>addOnPreStageChange</li><li>addOnStageChange</li></ul><p>Let’s see when to use each event based on your requirement.</p><h4><strong><em>1. addOnPreStageChange</em></strong></h4><p>Use “addOnPreStageChange” when validation or restrictions must occur <strong>before</strong> the stage changes.</p><h4><strong><em>2. addOnStageChange</em></strong></h4><p>Use “addOnStageChange” when business logic should execute <strong>after</strong> the stage has changed successfully.</p><p>Assume a Business Process Flow (BPF) is activated on the <strong>Candidate</strong> table with the following stages:</p><p><strong>Candidate Details → Course → Fee → Final</strong></p><h4><strong><em>addOnPreStageChange</em></strong></h4><p>When a user attempts to move from the current stage to the next stage, the active stage returned is the <strong>current stage</strong>, because the stage transition has not yet occurred.</p><p><strong>Candidate Details (Current Stage) → Course</strong></p><p>Here, the active stage is <strong>“Candidate Details”</strong>.</p><h4><strong><em>addOnStageChange</em></strong></h4><p>When a user successfully moves from one stage to another, the active stage returned is the <strong>destination stage</strong>, because the stage transition has already completed.</p><p><strong>Candidate Details → Course (Destination Stage)</strong></p><p>Here, the active stage is <strong>“Course”</strong>.</p><h4><strong>Scenario:</strong></h4><p><em>Prevent users from moving back to a previous stage. If they attempt to move backward, display an alert message and make the fields in the previous stage read-only using JS.</em></p><pre>function onLoad(executionContext){<br>   let formContext = executionContext.getFormContext();<br>   formContext.data.process.addOnPreStageChange(ValidateBeforeBPFStageChangeAndNotify);<br>   formContext.data.process.addOnStageChange(LockFieldsBasedOnBPFStage);<br>}<br><br>function ValidateBeforeBPFStageChangeAndNotify (executionContext) {<br>    let formContext = executionContext.getFormContext();<br>    let eventArgs = executionContext.getEventArgs();<br>    let activeStage = formContext.data.process.getActiveStage();<br>    if (activeStage.getName().toLowerCase().replaceAll(&quot; &quot;, &quot;&quot;) == &quot;course&quot;) {<br>        if (eventArgs.getDirection() == &quot;Previous&quot;) {<br>            var alertStrings = { confirmButtonLabel: &quot;Ok&quot;, text: &quot;Can&#39;t move to Previous Stage&quot;, title: &quot;Alert&quot; };<br>            var alertOptions = { height: 120, width: 260 };<br>            Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);<br>            eventArgs.preventDefault(); <br>            return; <br>        }<br>    }   <br>}<br><br>function LockFieldsBasedOnBPFStage (executionContext) {<br>    let formContext = executionContext.getFormContext();<br>    let activeStage = formContext.data.process.getActiveStage();<br>    if (activeStage != null) {<br>        if (activeStage.getName().toLowerCase().replaceAll(&quot; &quot;, &quot;&quot;) == &quot;course&quot;) {<br>            let fieldControls = formContext.getControl();<br>            if (fieldControls != null) {<br>                fieldControls.forEach(control =&gt; { <br>                     if (control.getName() == &quot;header_process_name&quot; || control.getName() == &quot;header_process_email&quot; || control.getName() == &quot; header_process_address&quot;) { <br>                         control.setDisabled(true); <br>                        } <br>                 });<br>            }<br>        }</pre><h4><strong><em>Code Explanation:</em></strong></h4><ul><li>getEventArgs() returns an object with methods to manage the events. Retrieve the active stage and verify whether the user is navigating to a previous stage. If backward navigation is detected, show an alert message, cancel the stage transition, and exit the function immediately.</li><li>Retrieve the active stage, validate the current BPF stage, and lock the required fields based on the stage.</li></ul><blockquote><strong><em>Important Note:</em></strong> When you use ‘preventDefault’ on a form with business process flows, the stage navigation may throw this error: “<strong>Unable to save form data due to web resource registered onSave invoking preventDefault”</strong>. Use <a href="https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/events/onprestagechange">onPreStageChange</a> to prevent this error.</blockquote><p>Thanks for reading.</p><p>Hope it helps you!!!</p><p><strong>Wait a moment. </strong>If you enjoyed this article, <strong><em>subscribe</em> </strong>to receive my latest articles directly in your inbox. Share it with your friends or colleagues who may find it helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5a75ea0b539" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Call a Power Automate Flow from Dynamics 365]]></title>
            <link>https://medium.com/@venkatavikasc/invoke-power-automate-flow-from-dynamics-365-crm-using-javascript-d11db25b5d41?source=rss-f38265f53b7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d11db25b5d41</guid>
            <category><![CDATA[cloud-flow]]></category>
            <category><![CDATA[trigger-power-automate]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[dynamics-365]]></category>
            <category><![CDATA[power-automate-flow]]></category>
            <dc:creator><![CDATA[Vikas]]></dc:creator>
            <pubDate>Sat, 03 Oct 2026 08:45:14 GMT</pubDate>
            <atom:updated>2026-11-17T10:23:51.449Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JutoxPepA2LVTYbz" /><figcaption>Photo by <a href="https://unsplash.com/@creatopy?utm_source=medium&amp;utm_medium=referral">Creatopy</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We will call a Power Automate flow with the ‘<em>When an HTTP request is received</em>’ trigger from JavaScript. The flow updates a Dynamics 365 CRM record and returns a response to the calling JavaScript code.</p><p>Follow the 3 steps below.</p><h3><strong>Step 1: Create a Power Automate Flow</strong></h3><ol><li>Navigate to <a href="https://make.powerautomate.com/">https://make.powerautomate.com/</a> and select your environment. Select <strong>Create</strong> from left navigation and choose <strong>Instant Cloud Flow</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*WYJQzRHTFLnwh_sl9X0o-Q.png" /></figure><p>2. Select the trigger as “<em>When an HTTP request is received</em>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*ROJQBQQQNquj8obRKuwxAA.png" /></figure><p>3. Choose the appropriate option for “<em>Who can trigger the flow?”.</em></p><h4><strong><em>Any user in my tenant:</em></strong></h4><p>Anyone signed in to your Microsoft 365 tenant can call it, and the request needs a valid Azure AD bearer token in the Authorization header.</p><h4><strong><em>Specific users in my tenant:</em></strong></h4><p>Only users listed in the trigger configuration, using email addresses or app user Object IDs separated by semicolons, will be authorized to call the Flow.</p><h4><strong><em>Anyone</em></strong><em>:</em></h4><p>Anyone with the full URL can trigger the Flow. This URL contains a SAS (Shared Access Signature) token at the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*uZeuPSv3jpPGV6rFd5XXXg.png" /></figure><p>4. If the request requires a body, provide a sample payload to generate the schema, and then click “Done”. Select the appropriate HTTP method, such as GET, POST, PUT, PATCH, or DELETE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*W5AUvJGjzHy8A3LFlKcHxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*iUQfBq7bWS1qH7law_4u3Q.png" /></figure><p>5. Update the candidate record with the Timings field option and provide the Row ID from the previous action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*0T4o2ZnwoP7GfjYUeRpoow.png" /></figure><p>6. Add a Response action, then configure the Headers and Body. Provide a sample response body by clicking the “Generate from Sample” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*0OKO-uLtCk3g9bBrhVA6hg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*K_U7I4HQiXATy-8bxILpyw.png" /></figure><p>7. Click the ellipsis (…) and select “Configure run after”. Enable the conditions under “When to run this action”, and then click “Done”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*EZEKeSLHEoElOq7eo7ngig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*wDrbRhF8e3BKybAfYA9vLA.png" /></figure><p>8. Select the <strong>+</strong> icon above the Success Response action and add a parallel branch with a Response action for Failure. Then, select “Configure run after”, choose the conditions for when this action should run, and click “Done”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*jDj99V8DVRFn4zsQ7t210w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*E-WjiKd7D6S0UDHSOzyzvg.png" /></figure><p>9. After saving the flow, an HTTP POST URL will be generated. Copy the POST URL and save it in a Notepad file.</p><h3><strong>Step 2: Write a JS code</strong></h3><p>1. Navigate to your CRM solution and create a web resource with the following details. Then, click ‘Save and Publish’.</p><p>Code — Add below JS code</p><p>File type — Select JavaScript</p><p>Name — Provide a meaningful name (for example, contact.js)</p><pre>function onSave (executionContext) {<br>let formContext = executionContext.getFormContext();<br>CallPowerAutomate(formContext);<br>}<br><br>function CallPowerAutomate (formContext) {<br>let recordId = formContext.data.entity.getId(). slice(1, -1);<br>let flowURL = &quot;&lt;HTTP POST URL&gt;&quot;;<br>let body = {<br>&quot;id&quot;: recordId<br>};<br>let req = new XMLHttpRequest();<br>req.open(&quot;POST&quot;, flowURL, true);<br>req.setRequestHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);<br>req.onreadystatechange = function () {<br>if (this.readyState === 4) {<br>req.onreadystatechange = null;<br>if (this.status === 200) {<br>let result = JSON.parse(this.response);<br>let message = result[&quot;message&quot;];<br>console.log(message);<br>} else {<br>console.log(this.statusText);<br>}<br>}<br>};<br>req.send(JSON.stringify(body));<br>}</pre><h4><strong><em>Code Explanation:</em></strong></h4><ul><li>We prepared an XMLHttpRequest and sent a POST request asynchronously using the Flow URL.</li><li>We set the Content-Type header to application/json.</li><li>Once the request was completed successfully and a response was received, the response was parsed into JSON format.</li></ul><p>2. Open the Entity form, select “Form Properties” and Add an OnSave event handler and then specify the JavaScript library, enter “onSave” as the function name, and enable the “Pass execution context as first parameter” option then click Save. Save and Publish the form.</p><h3><strong>Step 3: Validation</strong></h3><ol><li>Navigate to CRM, create a Candidate record with required details, and then click “Save”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*9Be-8F2XSSN4ydqkcVU2Eg.png" /></figure><p>2. Now we can see Timings field value is populated automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*JyjGwDnfQiCXBzhCzFZjew.png" /></figure><blockquote><strong>Note: </strong>If HTTP POST URL leaks or broken then you can <a href="https://learn.microsoft.com/en-us/power-automate/regenerate-sas-key">Regenerate the SAS Token</a> and use the new POST URL to call your flow.</blockquote><h4><strong>Closing Points:</strong></h4><ol><li>If your flow can be triggered by anonymous users, select “Anyone”.</li><li>If you want only authorized users to invoke the flow securely, select either “Any user in my tenant” or “Specific users in my tenant”, based on your requirements.</li></ol><p>Follow me on <a href="https://casketcrm.blogspot.com/">Casket CRM</a></p><p>Thanks for reading.</p><p>Hope it helps you!!!</p><p><strong>Wait a moment. </strong>If you enjoyed this article, <strong><em>subscribe</em> </strong>to receive my latest articles directly in your inbox. Share it with your friends or colleagues who may find it helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d11db25b5d41" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>