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)

Activity - Go to another form when status changed

(0) ShareShare
ReportReport
Posted on by 2,601

I've created an activity entity and when the user marks it as closed it I want to go to  another form.

I guess I would use the Save event to run some javascript but how can I detect what the previous activity status was, to know if  it has changed?

TIA

*This post is locked for comments

I have the same question (0)
  • Linn Zaw Win Profile Picture
    3,407 on at

    I'm not sure how you want to implement the script to go to another form on Save event.

    Because the Activity Status is still not change at OnSave event of the Form.

    But if you want to trigger at the "Save as Completed", you can add the context onSave event and check the SaveMode. For complete list of SaveMode, you can refer to the following MSDN article

    msdn.microsoft.com/.../gg509060.aspx

    function OnSave(context)

    {

    if (context != null && context.getEventArgs() != null)

    {

           var saveMode = context.getEventArgs().getSaveMode();

           if (saveMode == "58")

           {

               // Add Save as Completed code here

           }

       }

    }

  • Linn Zaw Win Profile Picture
    3,407 on at

    If you want to trigger it onLoad, you might have to create one hidden integer attribute and set it at OnSave event and compare with the current status code  value at OnLoad event.

  • CU21020959-0 Profile Picture
    2,601 on at

    I tried  getting the saveMode, it is 58 if the activity is closed using the button 'Mark Complete' but if I use the button 'Close SalesCall' (my activity is SalesCall) and choosing the status reason, which is how I want the users to do it, the saveMode is set to 5 (Deactivate).  Is this normal behaviour?

    I think the OnLoad event fires after Save on CRM 2011 and earlier.  They've fixed (!) this in CRM 2013 and the Onload event doesn't fire on save so I can't use that.

    I'm toying with cancelling the save using executionObj.getEventArgs().preventDefault(); and then firing my own event with Xrm.Page.data.save().then(successCallback, errorCallback); but haven't got it working yet.

  • Linn Zaw Win Profile Picture
    3,407 on at

    I guess the listed SaveMode are all that is triggering and it seems to be normal behaviour.

    The only additional SaveMode in CRM 2013 is 70 which is AutoSave.

    Can you specify more how it's not working?

    Does it proceed to save even though you call preventDefault() ?

    Or your own event is not triggering?

  • CU21020959-0 Profile Picture
    2,601 on at

    On the save event I cancel the save and then run the XRM Save event which has a callback which runs when the save has completed - see below code

    This issue I have now is that when the callback runs after the XRM Save event, the data hasn't committed.  I do an oData call to check and get the old values back.
     
    I'm open to any suggestions?  :) 

    var SaveActionRunOnce = false;

    function FormSave(executionObj) {
       if (executionObj != null && executionObj.getEventArgs() != null) {

          if (SaveActionRunOnce == false) {
             SaveActionRunOnce = true;
             executionObj.getEventArgs().preventDefault();
             Xrm.Page.data.save().then(successCallback, errorCallback);
          }
          else {
             SaveActionRunOnce = false;
          }
       }
    }


    function successCallback() {

    // get new values?

    }

  • Linn Zaw Win Profile Picture
    3,407 on at

    I'm new to CRM 2013 New Client API Methods and I don't have hands-on experience with them so far.

    But theoretically, you should get the updated values when you call oData query in the successCallback method since the callback functions is executed only after the save operation is completed.

  • CU21020959-0 Profile Picture
    2,601 on at

    That's exactly what I thought, it may be a bug in CRM 2013 - I don't know, I'm relatively knew to CRM.

    I'm guessing the save is still being committed so when the successCallBack runs it doesn't get the new data.

    I'm trying another way - setting a timer to run 1 second after the save event fires and then to get the new values.  

    Not ideal but I'm running out of options...  

  • Verified answer
    CU21020959-0 Profile Picture
    2,601 on at

    The only way I could get this to work was to run a SetTimeOut command in javascript on the OnSave and then use oData to get the new values.

  • tomnew481 Profile Picture
    40 on at

    I have same problem. How to run SetTimeOut command in Javascript?

  • CU21020959-0 Profile Picture
    2,601 on at

    Here is a code snippet which rechecks the data 2 seconds after saving:

    function FormSave() {
      setTimeout('CheckNewData()', 2000);  // 2000 is 2 seconds
    }


    function CheckNewData() {

    //Get guid of object on form
    var objectiD = Xrm.Page.data.entity.getId();

    // I use oData to get the updated values

    }

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