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 :
Microsoft Dynamics CRM (Archived)

How to handle save complete event?

(0) ShareShare
ReportReport
Posted on by

Hi ,

I need to set the field value in the form after save has been completed.Save can be invoked either autosave and manual save. how can i achieve this?

*This post is locked for comments

I have the same question (0)
  • Rajkumar Rajaraman Profile Picture
    on at

    Hi Surya,

    Put your javascript code onSave Event.

    Regards,

    R.Rajkumar

  • Community Member Profile Picture
    on at

    Hi Rajkumar,

    Thanks for your reply.

    I tried what you mentioned. But javascript code is executed before save completes. I just want to execute javascript after save complete.

  • Rajkumar Rajaraman Profile Picture
    on at

    Post your code here

  • Community Member Profile Picture
    on at

    Please find the code below:

    "setFormatAccount" Method is invoking on form save event

    var fieldValue  ="";

    function setFormatAccount(executionContext) {

       var eventArgs = executionContext.getEventArgs();

       var isSaved = false;

       if (eventArgs.getSaveMode() == 70 || eventArgs.getSaveMode() == 1) {

           isSaved = setFormat("telephone1");

           if (isSaved) {                  

    //Set the value to "telephone1" field after save completes

               Xrm.Page.getAttribute("telephone1").setValue(fieldValue);

           }

       }

    }

    function setFormat(field) {

    fieldValue = Xrm.Page.getAttribute(field).getValue();

       if (fieldValue != null) {

           var countrycode2 = fieldValue;

           if (fieldValue.startsWith('+')) {

               var countrycode1 = fieldValue.substr(0, fieldValue.indexOf(' '));

               if (countrycode1.length > 0)

                   countrycode2 = fieldValue.substr(countrycode1.length + 1);

               else

                   countrycode2 = countrycode1;

               if (countrycode2.startsWith('(')) {

                   countrycode2 = countrycode2.substr(countrycode2.indexOf(')') + 1);

               }

           }

           countrycode2 = countrycode2.replace('(', '');

           countrycode2 = countrycode2.replace(')', '');

           countrycode2 = countrycode2.replace('-', '');

           countrycode2 = countrycode2.replace('x', '');

           countrycode2 = countrycode2.replace(/_/g, '');

           countrycode2 = countrycode2.replace(/\s/g, '');

           Xrm.Page.getAttribute(field).setValue(countrycode2);

           return true;

       }

    }

  • Community Member Profile Picture
    on at

    Hi Surya,

    If you are using CRM 2013/2015 then we have a great feature for having a success callbacks,

    Xrm.Page.data.refresh(save).then(successCallback, errorCallback);

    or

    Xrm.Page.data.save().then(successCallback, errorCallback);

    Kindly go through below link

    msdn.microsoft.com/.../dn481607.aspx

    Hope its fits your requirement.

    Thanks,

    Vijay Bonam

  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at

    Hi Surya,

    It's fine, add this

    eventArgs.preventDefault();

    under

    if (eventArgs.getSaveMode() == 70 || eventArgs.getSaveMode() == 1) {

    and try the same

    Hope this helps.

    Regards,

    R.Rajkumar

    "Please mark my answer as verified if you found it helpful"

  • Community Member Profile Picture
    on at

    Hi Vijay,

    I am invoking the function at onsave of form itself. If i invoke Xrm.Page.data.save().then(successCallback, errorCallback);

    Then it will repeatedly invokes the save method. but actual save will not happen.

  • Community Member Profile Picture
    on at

    Ya Surya,

    I forgot that situation sorry my bad,

    You can write a plugin on post-operation, Then u can update that field

    Thanks,

    Vijay Bonam

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Surya,

    Any action after save transaction must be handled through plugin since CRM would call server side validation and next logic process after client facing process.

    Thanks.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Surya,

    You can write a plugin to update a field on save action has been completed.  You will need to select post- operation for this plugin because then plugin will execute after completing save actions.

    However, you can also write a workflow to update a field after your excution.

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans