Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Jscript - form refresh update - v9

Posted on by 310

Could someone help me please regarding my code below. I'm using Dynamics 365 v9.1 wave 2

I have a refreshForm function which im trying to trigger on a successful response via a POST call, however using the old method of xrm.page it works fine, however im trying future proof, however I can't get it to work using the new formContext method.

function refreshForm(executionContext){
         formContext = executionContext.getFormContext();
        //Xrm.Page.data.refresh(true);
        formContext.data.refresh();
}

function callFlow(primaryControl){
  var formContext = primaryControl;
	var returnGUID = formContext.data.entity.getId();
	var returnGUID = returnGUID.replace('{', '').replace('}', '');

if (typeof ($) === 'undefined') {
        $ = parent.$;
        jQuery = parent.jQuery;
        }

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://*******************************",
  "method": "POST",
   "headers": {
   "Content-Type": "application/json",
   "cache-control": "no-cache",
   "Postman-Token": "*****************************"
  },
  "processData": false,
  "data": "{\n	\"returnid\": \"("   returnGUID   ")\"\n}",
  "success": function () {console.log("Connection Successful");}
}

   $.ajax(settings).done(function (response) 
   {
        console.log(response);
        if (response.StatusCode == "SUC-999") {
            alert("Return Submission Successful");
            refreshForm();
        }
        else {
             alert("There has been an error. \n Error code and description:"   response.StatusCode   " - "   response.StatusDescription);
        }
   });
}

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Jscript - form refresh update - v9

    Hello,

    Try to use following code:

    function refreshForm(executionContext){
             formContext = executionContext.getFormContext();
            //Xrm.Page.data.refresh(true);
            formContext.data.refresh();
    }
    
    function callFlow(primaryControl){
      var formContext = primaryControl;
    	var returnGUID = formContext.data.entity.getId();
    	var returnGUID = returnGUID.replace('{', '').replace('}', '');
    
    if (typeof ($) === 'undefined') {
            $ = parent.$;
            jQuery = parent.jQuery;
            }
    
    var settings = {
      "async": true,
      "crossDomain": true,
      "url": "******",
      "method": "POST",
       "headers": {
       "Content-Type": "application/json",
       "cache-control": "no-cache",
       "Postman-Token": "****"
      },
      "processData": false,
      "data": "{\n	\"returnid\": \"("   returnGUID   ")\"\n}",
      "success": function () {console.log("Connection Successful");}
    }
    
       $.ajax(settings).done(function (response) 
       {
            console.log(response);
            if (response.StatusCode == "SUC-999") {
                alert("Return Submission Successful");
                formContext.data.refresh();
            }
            else {
                 alert("There has been an error. \n Error code and description:"   response.StatusCode   " - "   response.StatusDescription);
            }
       });
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans