Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

crm how to save a variable on form onsave

Posted on by Microsoft Employee

My crm on prem switches back a form field named imc_totalweight to default value after saving the form.

How can i save it after i change its value. How do i save the changed value of var weight on saving the form.I have defined a var weight to do another calculation which works fine but the original field value switches back to previous value on saving the form.

the small glimpse of function which does the calculation is:

function imc_calculatefreight_onchange()
{


var weight= Xrm.Page.getAttribute("imc_totalweight").getValue(); //here the value taken is accurate after changing the field value but after saving the form  imc_totalweight changes automatically.

if (calcFreight == true)
{

var weight = Xrm.Page.getAttribute("imc_totalweight").getValue();
//mycalculation;
if (error != "")
{
//mycalculation;

}
else if (freight != "")
{
//mycalculation;
}
}

}

I need to save the form field imc_totalweight on saving the form. 

*This post is locked for comments

  • AM-22040756-1 Profile Picture
    AM-22040756-1 405 on at
    RE: crm how to save a variable on form onsave

    You have to have a function for onsave, similar like:

    function onSave() {

    Xrm.Page.getAttribute("fieldName").setSubmitMode("always");

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: crm how to save a variable on form onsave

    after changing the total weight value the calculation of freight is accurate. but after saving the form the total weight field changes back to 50.

  • AM-22040756-1 Profile Picture
    AM-22040756-1 405 on at
    RE: crm how to save a variable on form onsave

    What u mean by "all cals are good after changing values" , changing values are done thro' plugins or js

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: crm how to save a variable on form onsave

    yes, it didn't work.

  • gdas Profile Picture
    gdas 50,085 on at
    RE: crm how to save a variable on form onsave

    Hi ,

    Did you try with my suggestion ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: crm how to save a variable on form onsave

    all calculations are good after changing values

    80546.2.png

    but after saving the form the field Total Weight goes back to 50:

    80546.2.png

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: crm how to save a variable on form onsave

    i am calling this function if freight calculation field is set to yes ..see the full code at:

    community.dynamics.com/.../271166

  • gdas Profile Picture
    gdas 50,085 on at
    RE: crm how to save a variable on form onsave

    Hello ,

    Please set the field properties setsubmitmode = always. Hope this helps.

    function imc_calculatefreight_onchange()
    {
    
     Xrm.Page.getAttribute("imc_totalweight").setSubmitMode("always");
    var weight= Xrm.Page.getAttribute("imc_totalweight").getValue(); //here the value taken is accurate after changing the field value but after saving the form  imc_totalweight changes automatically.
    
    if (calcFreight == true)
    {
    
    var weight = Xrm.Page.getAttribute("imc_totalweight").getValue();
    //mycalculation;
    if (error != "")
    {
    //mycalculation;
    
    }
    else if (freight != "")
    {
    //mycalculation;
    }
    }
    
    }
  • AM-22040756-1 Profile Picture
    AM-22040756-1 405 on at
    RE: crm how to save a variable on form onsave

    Hi ,

    When you are calling  imc_calculatefreight_onchange() function ?

    I don't see you set value for this field imc_totalweight.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans