Skip to main content

Notifications

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

  • Suggested answer
    Kenneth Ariel Chaves Herrera Profile Picture
    on at
    RE: Enabling Auto-Save in a JS code

    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.

  • Community Member Profile Picture
    on at
    RE: Enabling Auto-Save in a JS code

    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

  • Aneeqa Pervaiz Profile Picture
    240 on at
    RE: Enabling Auto-Save in a JS code

    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
    RE: Enabling Auto-Save in a JS code

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

  • Aneeqa Pervaiz Profile Picture
    240 on at
    RE: Enabling Auto-Save in a JS code

    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
    RE: Enabling Auto-Save in a JS code

    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
    RE: Enabling Auto-Save in a JS code

    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?

  • Suggested answer
    Thomas David Dayman Profile Picture
    11,323 on at
    RE: Enabling Auto-Save in a JS code

    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

  • Community Member Profile Picture
    on at
    RE: Enabling Auto-Save in a JS code

    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?

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106 Most Valuable Professional

#3
Eugen Podkorytov Profile Picture

Eugen Podkorytov 87

Overall leaderboard

Product updates

Dynamics 365 release plans