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 call save complete on Save operation.

(1) ShareShare
ReportReport
Posted on by

Hello,

Please help me on this. Struggling for a long time.

Quote record, Currently it is in draft state, if a specific field is marked as true then activate the record (No default button usage). 

So to do that operation, I have written the soap message to activate it and registered this on Save operation.

Now the problem is, before the save operation gets completed the activation of the quote is happening, after that when it continues to the save operation it is failing to save because the record is activated and moved to read only.

Please do not suggest me to do it in the server side because after his activation operation I am again firing another soap message for converting the quote in to order and I should open the created order record which is not possible with the server side code.

For this, I have tried the below code. It is saving the record but it is not continuing to the next operation.

Here is my code:

Tas.Quote = {

activateQuoteRequestOnSaveComplete: function (quoteContext) {
if (!isAlreadySaved) {
isAlreadySaved = true;
quoteContext.getEventArgs().preventDefault();

activateQuote = Xrm.Page.getAttribute("tas_signsowandsend").getValue() &&
Xrm.Page.getAttribute("tas_signsowandsend").getIsDirty();
}
else {
isAlreadySaved = false;
}
//activateQuote = Xrm.Page.getAttribute("tas_signsowandsend").getValue() &&
// Xrm.Page.getAttribute("tas_signsowandsend").getIsDirty();
if (isAlreadySaved)
Xrm.Page.data.save().then(Tas.Quote.activateQuoteRequest,
function (errorCode, message) {
});
},

This is saving the record but not continuing to activate request.

Please suggest on this.

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi,

    use the java script setTimeout function ... it keep stop you for sometime

  • Community Member Profile Picture
    on at

    use the Java Script function setTimeOut . this will keep you stop for sometime

  • Suggested answer
    Rugved Gokhale Profile Picture
    on at

    Hi Shrekanth,

    Looks like you have registered a java script on save. In Dynamics CRM, your 'On Save' JavaScript handlers will always run before platform's save operation no matter what you do. Thats the design.

    So if you need to activate quote from onSave script as a separate service call, you need to prevent the entity save using 'https://msdn.microsoft.com/en-us/library/gg509060.aspx' .

    This should let your script work the way it is and would cancel the platform save as well. ALso, cancelling save operation using PreventDefault does not stop 'On Save Java Script' handlers from running. So additionally you can check if your field is marked as true before you prevent save operation.

  • Community Member Profile Picture
    on at

    How can it solve my issue. Can you please explain me a bit more.

  • Community Member Profile Picture
    on at

    The webpage you provided no longer exist. Can you please post a new page or can you explain me a bit more.

  • Suggested answer
    Rugved Gokhale Profile Picture
    on at

    Some special character was added to the link so it was not directing you properly. If it still didn't work search for Save event arguments for Client-side reference.

    Copy & paste this in browser :- https://msdn.microsoft.com/en-us/library/dn481600.aspx 

    Approach :-

    1. Pass client side context object in the JScript handler where you are activating the quote.  This can be done by clicking the 'pass context as first parameter' checkbox in Form Properties in Handler Properties popup.

    2. Once this is done & you have context in your JScript method, you can use the event arguments supported by context to call preventDefault() method.

    e.g. :- contextObj.getEventArgs().preventDefault()

    Please note, check for proper conditions before calling this method as this will not hit sever for completing current save operation. Hence call this method only in case of activating your quote. Once you call this, the save operation wont be called with your quote activation.

     

    Please mark it as an answer if it helps :) !

  • Community Member Profile Picture
    on at

    I am already doing this one. Please check my code. This will stop the current operation. And after that if I call my activate request it activates the quote and marks the forms as read only. So that I can never save the attribute just changed. But I should this attribute then should fire activate operation.

    Please help....

  • Rugved Gokhale Profile Picture
    on at

    You are correct. I understood your issue right now :) You can try below approach but I have not tried it myself.

    Option 1:- (Cleaner approach)

    In this case, if you could afford a deviation in your flow then instead of checking that field and depending on save operation to trigger your activation, instead you can try creating the custom action. In actions, you can mix multiple SDK operations into one (like in this case, save and then activate) then add output parameter typed 'entity reference' which will hold the reference to generated order and hence it will be return to the caller of this action.

    Check this for details on creating your own actions :- msdn.microsoft.com/.../dn481600.aspx

    Once your action is ready, you can just call this custom action (using similar service call instead of activate) on click of a custom ribbon button. As you will define output parameter as order reference id, you'll get the same in response. Then use it to open that record.

    Check this for calling action from javascript :- www.plusconsulting.com/.../Post.aspx

    Option 2 :- (Crude approach)

    - Give a retrieveMultiple call on click of ribbon button as stated above.

    - Retrieve Multiple would be based on any dummy query which won't return you anything.

    - write a plugin on RetrieveMultiple message, do your required operation in this plugin,

    -  Once done, add the generated order id in the output parameters inside BusinessEntityCollection.

    - This collection could be accessed at client side as a retrieveMultiple response

    - Extract the Id & proceed for opening record.

  • Suggested answer
    MilindP Profile Picture
    1,019 on at

    use the addOnSave on the onload of the form where function name is your function which is activating it.

    Xrm.Page.data.entity.addOnSave(<function name>)

    so the function which you are adding on On save will get executed after the save operation is complete.

    see more information below

    https://msdn.microsoft.com/en-us/library/Gg334720.aspx

    hoping this is what you are looking

  • Community Member Profile Picture
    on at

    Hi Milind,

    I have already tried this approach. As per the site, the event is last in the pipeline in the client side but not on the server side. So the server side activation will happen before the save gets completed. Again causing the same error.

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