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

Announcements

News and Announcements icon
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,985 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Nagaraju_Matta Profile Picture

Nagaraju_Matta 119

#2
ManoVerse Profile Picture

ManoVerse 78 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 66 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans