Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

Xrm.Page.data.refresh

Posted on by 70

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.

  • RE: Xrm.Page.data.refresh

    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.

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Xrm.Page.data.refresh

    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 

  • RE: Xrm.Page.data.refresh

    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
    cloflyMao 25,198 on at
    RE: Xrm.Page.data.refresh

    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

  • RE: Xrm.Page.data.refresh

    Yes, I am creating new record

    CallAction.txt

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Xrm.Page.data.refresh

    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

  • RE: Xrm.Page.data.refresh

    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
    cloflyMao 25,198 on at
    RE: Xrm.Page.data.refresh

    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

  • RE: Xrm.Page.data.refresh

    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
    cloflyMao 25,198 on at
    RE: Xrm.Page.data.refresh

    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

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans