Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Unable to get property 'then' of undefined or null reference

Posted on by Microsoft Employee

Hello everyone,

I have an error happens at Xrm.Page.data.save(saveOptions).then(successCallback, errorCallback) function.

My situation is like following: 

  • I have a plugin that checks for some business rule at (Service Appointment) form.
  • Business Rule is to prevent any user of creating new (Service Appointment) if he is already have another (Scheduled) one.
  • I created the plugin as (PreCreate) to run before save new (Service Appointment)
  • Plugin working normally, and throw (InvalidPluginExecutionException) when business rule is violated
  • Now I wrote a JavaScript to handle (InvalidPluginExecutionException) to show error message as a Form notification using ( Xrm.Page.ui.setFormNotification)
  • I attached that new JavaScript to (Service Appointment) Form to be fired (OnSave) event.
  • Following code clarify the JavaScript code
function StartSave() {
    //========================================================
    //Clear old notifications
    Xrm.Page.ui.clearFormNotification();

    //Save Form data
    Xrm.Page.data.save().then(SuccessCallback, ErrorCallback);
}
  • Now error happens at (Xrm.Page.data.save().then). Error is (Unable to get property 'then' of undefined or null reference).

I don't know why this error happens and how to know its root cause. Is OnSave event is not correct?? 

I used following links samples to mimic its behavior:

I use CRM 2015 on Premise.

Thanks in advance.

Kind Regards,

*This post is locked for comments

  • Suggested answer
    Drew Poggemann Profile Picture
    Drew Poggemann 9,079 on at
    RE: Unable to get property 'then' of undefined or null reference

    Hi Wael,

    According to the following article:  https://msdn.microsoft.com/en-us/library/dn481607.aspx it looks like the save will only work for specific "updated entities" as identified here:  https://msdn.microsoft.com/en-us/library/gg328261.aspx#BKMK_UpdatedEntties

    It does not look like service appointment is in this list so maybe this is why it is not working?

    Hope this helps!


    Thanks,

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