web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

formContext.data.refresh() does not call OnLoad

(0) ShareShare
ReportReport
Posted on by 659

Hi,

I am having troubles using the refresh() function properly.

Following scenario:

I am developing an Order Confirmation Dialog as a "Custom Page".

In the Custom Page, Users can confirm the Order which should close the Custom Page and refresh the Dynamics Form.

Additionally, once the Order is confirmed, all fields should be Read-Only.  

  1. Custom Page: Patches Order Statuscode and Back() to return to Dynamics -> works fine
  2. JavaScript registered "On Load" on the Order Form which disables all Controls -> works fine when using the UI "Refresh" Button or when F5 or when navigating to a record 
  3. In the Callback of the Custom Page I try to refresh the Form to show the new updated Status code -> doesnt work

Find my JS Code below. The debugger in the refresh Callback (line 31) does not get triggered. Additionally I shouldn't even need the manual call to the disableAllFields method as the refresh Method should fire the event already as can be seen in the documentation (https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/events/form-data-onload)

pastedimage1637845682572v1.png

function openConfirmPage(primaryControl, id)
{
	debugger;
	var recordId = id.replace("{", "").replace("}", "");

    console.log("Id: "   recordId);

	var pageInput = {
		pageType: "custom",
		name: "prefix_salesorderconfirmation_581cd",
        entityIdField: "salesorder",
        recordId: recordId
	};

	var navigationOptions = {
		target: 2,
		position: 2,
		width: {
			value: 80, unit: "%"
		},
		title: "Confirm Sales Order"
	};
	Xrm.Navigation.navigateTo(pageInput, navigationOptions)
		.then(

	function ()
	{
        debugger;
		primaryControl.data.refresh().then(
            function () {
                debugger;
            	disableAllFields(primaryControl);
            }

		);
	}).catch (
        function (error)
        {
            console.log(error);
        });
}


function disableAllFieldsHelper(executionContext) {
    debugger;
   var formContext = executionContext.getFormContext();
   disableAllFields(formContext);
}

function disableAllFields(formContext) {
  debugger;
   var status = formContext.getAttribute("statecode").getValue();
   var statusReason = formContext.getAttribute("statuscode").getValue();
   
   if(statusReason == 1 || status != 0) return;

   formContext.ui.controls.forEach(function (control, i) {
       if (control && control.getDisabled && !control.getDisabled()) {
           control.setDisabled(true);
       }

   });
}

I have the same question (0)
  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    I see there is some syntax error in your code. I have modified your code below.

    function openConfirmPage(primaryControl, id)
    {
    	debugger;
    	var recordId = id.replace("{", "").replace("}", "");
    
        console.log("Id: "   recordId);
    
    	var pageInput = {
    		pageType: "custom",
    		name: "prefix_salesorderconfirmation_581cd",
            entityIdField: "salesorder",
            recordId: recordId
    	};
    
    	var navigationOptions = {
    		target: 2,
    		position: 2,
    		width: {
    			value: 80, unit: "%"
    		},
    		title: "Confirm Sales Order"
    	};
    	Xrm.Navigation.navigateTo(pageInput, navigationOptions)
    		.then(
    
    	function ()
    	{
            debugger;
    		primaryControl.data.refresh().then(
                function () {
                    debugger;
                	disableAllFields(primaryControl);
                }
    
    		);
    	},
            function (error)
            {
                console.log(error);
            });
    }
    
    
    function disableAllFieldsHelper(executionContext) {
        debugger;
       var formContext = executionContext.getFormContext();
       disableAllFields(formContext);
    }
    
    function disableAllFields(formContext) {
      debugger;
       var status = formContext.getAttribute("statecode").getValue();
       var statusReason = formContext.getAttribute("statuscode").getValue();
       
       if(statusReason == 1 || status != 0) return;
    
       formContext.ui.controls.forEach(function (control, i) {
           if (control && control.getDisabled && !control.getDisabled()) {
               control.setDisabled(true);
           }
    
       });
    }

    Let me know if this works.

    Please mark my answer verified if this is helpful!

  • SErf Profile Picture
    659 on at

    Thank you Bipin.

    This indeed solved the issue so I can call the function myself.

    Still it seems if I comment out line 32 the Function call to the disable function. The OnLoad event is not fired by the refresh() method.

    I can live with the workaround of calling it myself, still strange though.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 72 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans