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,...
Unanswered

Xrm.Page.data.refresh

(0) ShareShare
ReportReport
Posted on by 76

Hello,

In web resource after some logic, I try to refresh page, but it enter into errorCallback function. How can I understand why? How can I get an exception ?

...

window.parent.Xrm.Page.data.refresh(true).then(function () {
window.parent.Xrm.Page.data.save();
debugger;
// do something
}, function () {
debugger;
//
alert('Error from refresh');
});

...

Thanks.

I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at

    Hi Marina,

    It will returns an object when error callback function executed.

    https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/dn481607(v=crm.8)?redirectedfrom=MSDN#refresh

    try this:

    window.parent.Xrm.Page.data.refresh(true).then(function() {
      window.parent.Xrm.Page.data.save();
      debugger;
    }, function(error) {
      alert(error.message);
    });

    If above not works, surround your function with try catch block to test again:

    try {
      window.parent.Xrm.Page.data.refresh(true).then(function() {
        window.parent.Xrm.Page.data.save();
        debugger;
      }, function() {
        debugger;
      });
    } catch (error) {
      alert(error.message);
    }

    Regards,

    Clofly

  • Marina Karapetyan Profile Picture
    76 on at

    Hi, Clofly

    debugger stop here

    try {

                               window.parent.Xrm.Page.data.refresh(true).then(function () {

                                   window.parent.Xrm.Page.data.save();

                                   debugger;

                                   loader.css("display", "none");

                               }, function () {

                                   debugger;

                               });

                           }

                           catch (error) {

                               debugger;

                               alert(error.message);

                           }

    It is errorCallback of refresh, isn't it ?

  • cloflyMao Profile Picture
    25,210 on at

    Hi Marina,

    Yes, the errorCallback has been executed,

    can you get error.message from it?

    window.parent.Xrm.Page.data.refresh(true).then(function() {
      window.parent.Xrm.Page.data.save();
      alert("Ok");
      loader.css("display", "none");
    }, function(err) {
      debugger;
      alert("An err has occured: "   err.message);
    });

    I got the error message successfully when I execute Xrm.Page.data.refresh to refresh an account record which required Account Name was not populated.

    pastedimage1577237419687v1.png

    try catch block is not necessary, we can get error message directly from error callback.

    Regards,

    Clofly

  • Marina Karapetyan Profile Picture
    76 on at

    Hi, Clofly

    message"Cannot read property 'message' of null"

    17504.Error.png

    Your code is in js script of form? or in WebResource ?

    Thank you.

  • cloflyMao Profile Picture
    25,210 on at

    Hi Marina,

    It seems that you're creating a new account record from web resource,

    could you share me your web resouce to test or just core function if possible?

    have you checked potential reason which could cause error callback?

    Such as there was no valid data in your req.send JSON object.

    Regards,

    Clofly

  • Marina Karapetyan Profile Picture
    76 on at

    Yes, I am creating new record

    CallAction.txt

  • cloflyMao Profile Picture
    25,210 on at

    Hi Marina,

    I hadn't custom action and just created web resource and it would update Description field of current account record,

    the err.message was available when I did save button if Name field was null.

    Please try my web resouce and leave Name field empty for test.

    
        
        Update account manually
    
    
    
    
        
            
            



    Regards,

    Clofly

  • Marina Karapetyan Profile Picture
    76 on at

    I try WebResource without action, but again message: "Cannot read property 'message' of null"

    err is null. Your version is v9.0, my is v8.2. Can it be the reason that my errorCallback can not read err.message ?

  • cloflyMao Profile Picture
    25,210 on at

    Hi Marina,

    err.message has been supported since CRM2013.

    Did you also run the web resource in UCI?

    I insert debugger and left Name field null to test, 

    in UCI, I could jump into break point and err object was available,

    while in legacy web client, I just received an error from formcontrol.js, which said that cannot read property 'errorCode' of null.

    Both test were based on main form.(Account -> Account form)

    From your situation, it seems that you could create a new account record successfully with an action,

    the issue is only that you can't get error callback,

    so I suggest that you open the new record directly with window.parent.Xrm.Utility.openEntityForm("account",newEntityId) as alternative to window.parent.Xrm.Page.data.refresh(true).

    My modified web resource, it will create a new account and then open the new record.

    
    
    
      
      Create account manually
    
    
    
      






    It will create a new account record.

    Regards,

    Clofly 

  • Marina Karapetyan Profile Picture
    76 on at

    Hi, Clofly

    I tried this: window.parent.Xrm.Utility.openEntityForm("account",newEntityId)

    It does not work, maybe because of version.

    The reason: there was a Required field, which stay empty. But as I could not find it, so walked through all the fields(getEntity().getAttributes().getAll()) and setRequiredLevel("None") then refresh page.

    window.parent.Xrm.Page.data.refresh(true).then(function () {

    window.parent.Xrm.Page.data.save();

    Thank you very much for your support. I'll never forget it.

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 73 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 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