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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Enabling Auto-Save in a JS code

(0) ShareShare
ReportReport
Posted on by 240

Hello, 

I have a JS code which runs on Account form onLoad and rollup field onChange - and copies the value from a rollup field to a temp field. I am using that temp field as a trigger in my workflow to set the account status accordingly. 

However, I have noticed that whenever the system updates the rollup field, it does copy over to the temp field fine, BUT does not trigger the workflow since the form does not save after the temp field updates. I added lines of code to autosave. But it is not working as expected. Note that I do have auto-save turned on in System Settings, but the save does not trigger when the temp field populates. 

function new_openopp ()
{
  var formOP = Xrm.Page.getAttribute("opendeals").getValue();
  Xrm.Page.getAttribute("openopportunitiestemp").setValue(formOP);

function AutoSaveForm() {
    if (Xrm.Page.ui.getFormType() == 2) { //only for form update
        var intervalId = window.setInterval(
         function () {
             window.clearInterval(intervalId);
             Xrm.Page.data.entity.save()
         }, 3000); 
    }
}}

Is there anything missing here? Would appreciate any help here. 

Thanks, 
Aneeqa

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

    Hi,

    as I understand you work with OnChange event to take the value from rollup field to temp field

    and then the temp field trigger a workflow

    so my question here is it save temp field when you open the record?

    and also, did you try to move the save line under the last line in new_openopp function?

  • Suggested answer
    Thomas David Dayman Profile Picture
    11,323 on at

    You may want to recalculate the rollup field in JavaScript, then copy the value to the temp field. This will ensure that you always have the correct value - vjcity.blogspot.com/.../refreshing-rollup-field-using-javascript.html

  • Aneeqa Pervaiz Profile Picture
    240 on at

    Hey,

    Moving the save line in the first function helped. However, is there anyway to have the temp field populated when the form is NOT open?  If the form is closed when rollup changes, the temp field does not populate. Since I have the code added to form onLoad as well, so when I open the account form, the temp field populates, form saves and status updates. But this is not a practical way.

    How do I get the temp field to update from rollup with the form closed?

  • Community Member Profile Picture
    on at

    Ok JS not help in this situation because its a client side

    Try to do your business in plugin or Custom Activity ,

    Or you can do a workflow to update temp field then run the main workflow based on this field.

  • Aneeqa Pervaiz Profile Picture
    240 on at

    If I could update temp field with a workflow, I would not have gone with any other option. I cannot trigger the workflow with update of a rollup field, hence I had to do JS. But JS is not enabling the temp field update with form closed - which means that the user would need to go back to the form, open it - to enable JS to kick into action and run the workflow.

  • Community Member Profile Picture
    on at

    Yes, you can re structured this cycle with WF, or Plugins

  • Aneeqa Pervaiz Profile Picture
    240 on at

    Do you mean using a business rule to populate temp field and that triggering the workflow?

    But rollup field change cannot trigger workflow or business rule - that is the limitation. Can you please tell what you mean by restructuring the cycle?

    Thanks,

  • Community Member Profile Picture
    on at

    What I meant by saying "Restructuring the cycle", that you will revamp all of this business (populate rollup field into temp field" by using another approach.

    If you want to copy data from Rollup field (datatype Numbers) to another field with same datatype , you can use this approach in Business rules.

    But If you work with two different fields types, so you can  do a business rule also, to work with Rollup field ,for example

    If rollup field greater than x , so put in Temp field a flag (lets say True)

    Create this business rule with scope "Entity"

    Then they will trigger your workflow

  • Suggested answer
    Kenneth Ariel Chaves Herrera Profile Picture
    on at

    The blog post on how to manage AutoSave using JavaScript might help.

    CRM 2013: JavaScript – How to Manage Form AutoSave - Microsoft Dynamics CRM Community

    If this answers your question, please check it as verified.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans