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)

Adding values of multiple fields in Dynamics CRM

(0) ShareShare
ReportReport
Posted on by 320

Hello, I am using the following code for adding the values of fields in dynamics crm

function CalculateEffort ()
{
var sumServices=
Xrm.Page.getAttribute("new_effortprojectmanagement").getValue(); +
Xrm.Page.getAttribute("new_effortanalysis").getValue(); +
Xrm.Page.getAttribute("new_effortconfiguration").getValue(); +
Xrm.Page.getAttribute("new_effortdatamigration").getValue(); +
Xrm.Page.getAttribute("new_effortdevelopment").getValue(); +
Xrm.Page.getAttribute("new_effortqualityassurance").getValue(); +
Xrm.Page.getAttribute("new_efforttesting").getValue(); +
Xrm.Page.getAttribute("new_effortuserdocumentation").getValue(); +
Xrm.Page.getAttribute("new_efforttraining").getValue(); +
Xrm.Page.getAttribute("new_effortdeployment").getValue();

Xrm.Page.getAttribute("new_totaleffortrequired").setValue(sumServices);
}

I cannot find any mistakes in the above code (as per my knowledge). It gives an error on saving the form.

ReferenceError: CalculateEffort is not defined
at eval (eval at RunHandlerInternal (abc.../ClientApiWrapper.aspx), <anonymous>:1:1)
at RunHandlerInternal (abc.../ClientApiWrapper.aspx)
at RunHandlers (abc.../ClientApiWrapper.aspx)
at ExecuteHandler (abc.../ClientApiWrapper.aspx)
at Mscrm.TurboForm.Control.CustomScriptsManager.$Cb_1 (abc.../formcontrols.js)
at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandler (abc.../formcontrols.js)
at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandlerByDescriptor (abc.../formcontrols.js)
at abc.../formcontrols.js
at abc.../global.ashx
at Mscrm.TurboForm.Control.Data.DataEntity.$Dd_1 (abc.../formcontrols.js)

What could be the cause of it?

Thank you.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Huzefa,

    Can you try publish all customization and refresh? This usually happens due to caching issue unless there is any syntax error.

    I am assuming you have added the library on the form.

    Hope this helps.

  • Huzefa Bootwala Profile Picture
    320 on at

    Hello,

    Yes I did refresh. Sometimes it shows the above error whereas sometimes it takes the value of the first field and displays it.

    It does not add all the fields.

    Thank you.

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    The error "CalculateEffort is not defined" should not come again unless there is syntax error. For the other issue " it takes the value of the first field and displays it", the reason could be it is blank?

    I would suggest instead of doing all this in one statement, break it down and add it. Something like this-

    =========================

    function CalculateEffort() {

       var effort1 = Xrm.Page.getAttribute("new_effortprojectmanagement").getValue();

       var effort2 = Xrm.Page.getAttribute("new_effortanalysis").getValue();

       var effort3 = Xrm.Page.getAttribute("new_effortconfiguration").getValue();

       var effort4 = Xrm.Page.getAttribute("new_effortdatamigration").getValue();

       var effort5 = Xrm.Page.getAttribute("new_effortdevelopment").getValue();

       var effort6 = Xrm.Page.getAttribute("new_effortqualityassurance").getValue();

       var effort7 = Xrm.Page.getAttribute("new_efforttesting").getValue();

       var effort8 = Xrm.Page.getAttribute("new_effortuserdocumentation").getValue();

       var effort9 = Xrm.Page.getAttribute("new_efforttraining").getValue();

       var effort10 = Xrm.Page.getAttribute("new_effortdeployment").getValue();

       var sumServices = effort1 + effort2 + effort3 + effort4 + effort5 + effort6 + effort7 + effort8 + effort9 + effort10;

       // alert(sumServices);

       Xrm.Page.getAttribute("new_totaleffortrequired").setValue(sumServices);

    }

    ========================================

    You can also put alert for each of the value to see if there is any value or not.

    Hope this helps.

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Huzefa,

    Please try removing the semicolons and modify the code as shown below.

    function CalculateEffort()
    {
    var sumServices=
    Xrm.Page.getAttribute("new_effortprojectmanagement").getValue() + 
    Xrm.Page.getAttribute("new_effortanalysis").getValue() + 
    Xrm.Page.getAttribute("new_effortconfiguration").getValue() + 
    Xrm.Page.getAttribute("new_effortdatamigration").getValue() + 
    Xrm.Page.getAttribute("new_effortdevelopment").getValue() + 
    Xrm.Page.getAttribute("new_effortqualityassurance").getValue() +
    Xrm.Page.getAttribute("new_efforttesting").getValue() + 
    Xrm.Page.getAttribute("new_effortuserdocumentation").getValue() + 
    Xrm.Page.getAttribute("new_efforttraining").getValue() + 
    Xrm.Page.getAttribute("new_effortdeployment").getValue();
    Xrm.Page.getAttribute("new_totaleffortrequired").setValue(sumServices);
    }

    Hope this helps.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Huzefa,

    you have to remove the ";" at the end of each getValue() line because it brokes the script.

    Please, let us know.

    If you found the answer helpful, please mark as Verified 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Huzefa Bootwala Profile Picture
    320 on at

    Hello,

    The code worked fine.

    Thanks so much.

  • Huzefa Bootwala Profile Picture
    320 on at

    Hello,

    Yes it worked after removing the semi colons.

    Thank you.

  • Huzefa Bootwala Profile Picture
    320 on at

    Hello,

    Thank you for the above code.

    It worked fine after removing the semi colons.

    Thanx.

  • Praveen Kumar Ellappa Profile Picture
    160 on at

    Hi,

    I am in a similar scenario. I am trying to sum up few field values and update it to a field through below code. I have added this function in all fields (stl_cpdu1, stl_cpdu2, etc.)...Is this correct?

    /Function to add all CPDUs values

    function Event_Update_TotalCPDU ()

    {

    var CalculatedCPDU=

    Xrm.Page.getAttribute("stl_cpdu1").getValue() +

    Xrm.Page.getAttribute("stl_cpdu2").getValue() +

    Xrm.Page.getAttribute("stl_cpdu3").getValue() +

    Xrm.Page.getAttribute("stl_cpdu4").getValue() +

    Xrm.Page.getAttribute("stl_cpdu5").getValue() +

    //Set value for Total CPDU

    Xrm.Page.getAttribute("stl_cpdu").setValue(CalculatedCPDU);

    }

    But, I am getting below error message in the form after entering the value.

    @xxxx.xxx.dynamics.com/.../ClientApiWrapper.aspx line 157 > eval:1:1

    RunHandlerInternal@xxxx.xxx.dynamics.com/.../ClientApiWrapper.aspx

    RunHandlers@xxxx.xxx.dynamics.com/.../ClientApiWrapper.aspx

    ExecuteHandler@xxxx.xxx.dynamics.com/.../ClientApiWrapper.aspx

    $Ce_1@xxxx.xxx.dynamics.com/.../formcontrols.js

    executeHandler@xxxx.xxx.dynamics.com/.../formcontrols.js

    executeHandlerByDescriptor@xxxx.xxx.dynamics.com/.../formcontrols.js

    getHandler/<@xxxx.xxx.dynamics.com/.../formcontrols.js

    getHandler/<@xxxx.xxx.dynamics.com/.../global.ashx

    fireOnChange@https:/XXXX.XXX.dynamics.com/_static/form/formcontrols.js?ver=-385382622:12178:13

    setValueInternal@xxxx.xxx.dynamics.com/.../formcontrols.js

    setValue@xxxx.xxx.dynamics.com/.../formcontrols.js

    $3e_2@https:/XXXX.XXX.dynamics.com/_static/form/formcontrols.js?ver=-385382622:25826:9

    Function.createDelegate/<@XXXX.XXX.dynamics.com/_static/_common/scripts/MicrosoftAjax.js?ver=-385382622:24:16

    b@xxxx.xxx.dynamics.com/.../MicrosoftAjax.js

    Thanks,

    Praveen.

  • Huzefa Bootwala Profile Picture
    320 on at

    Hi Praveen,

    Are you firing the code on onSave event of the form or onChange event of a field?

    It is better to open up a new thread as this thread is already verified and won't be noticed by others.

    Thanx.

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