Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

CRM Development- Javascript

Posted on by 1,942

Hi all,

I have a decimal field with precision zero, using javascript i have to increment this decimal value by 1 and the event is onSave and below is my code

function increament () {
var value = Xrm.Page.getAttribute("new_revisionid").getValue()
var isDirty = Xrm.Page.data.entity.getIsdirty ();
var finalvalue = null;
if (isDirty == True){
finalvalue = value++;
Xrm.Page.getAttribute("mew_revisionid").setValue("finalvalue");
}
}

But i receive the following error: "increment is not defined at eval"

I am not sure where this is going wrong, can anyone suggest me inputs here?

*This post is locked for comments

  • Suggested answer
    Yadnyesh Kuvalekar Profile Picture
    Yadnyesh Kuvalekar 4,102 on at
    RE: CRM Development- Javascript

    If you want to track only field changes happen on form, then your current solution is fine. If you want to know the changes occurred from any sources, then I would suggest you to go for workflow. Also, think of auditing if you want. With auditing you can check what was the old value, who changes it at what time and new value.

  • Vighnesh Profile Picture
    Vighnesh 1,942 on at
    RE: CRM Development- Javascript

    Hi Yadnyesh, firstly thank you for brief explanation & pointing those syntax errors.

    My logic is that whenever any field value is changed in the form i should update the revision number (increment) and to achieve this i am using Javascript which will be triggered on save.

  • Suggested answer
    Yadnyesh Kuvalekar Profile Picture
    Yadnyesh Kuvalekar 4,102 on at
    RE: CRM Development- Javascript

    Hi Vighnesh,

    Can you tell about your business logic? What are you trying to achieve using this code?

    Also, have you tried debugging your code? If not, please debug your code and tell on which line you are getting this error? I feel that you are not getting value in your value variable.

    Also, when you are using finalvalue = value++; it will not store the incremented value in finalvalue because post increment statements work as below:

    Statement: finalvalue = value++;

    Execution steps:

    1. finalvalue = value;

    2. value = value + 1;

    So, your business logic might be incorrect if you are not aware of this.

    In last statement, you have put double quotes. Remove the same. Also, in logical name of field there seems to be spelling mistake. You have written mew_.

    Replace Xrm.Page.getAttribute("mew_revisionid").setValue("finalvalue"); by Xrm.Page.getAttribute("new_revisionid").setValue(finalvalue);

  • Vighnesh Profile Picture
    Vighnesh 1,942 on at
    RE: CRM Development- Javascript

    Guido, thank you very much for your correction even i had done the same thing before you explained. Below is the final code

    function reviseid () {

    var value = Xrm.Page.getAttribute("new_revisionid").getValue();

    var isDirty = Xrm.Page.data.entity.getIsDirty();

    if (isDirty) {

    value++;

    Xrm.Page.getAttribute("new_revisionid").setValue(value);

    }

    }

  • Vighnesh Profile Picture
    Vighnesh 1,942 on at
    RE: CRM Development- Javascript

    Hi Andrii, your syntax did work. The only change i have made is IsDirty.

    Thanks a lot

  • Vighnesh Profile Picture
    Vighnesh 1,942 on at
    RE: CRM Development- Javascript

    Thanks Andrii for your response, even this is also not working and is showing the same error.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: CRM Development- Javascript

    Hi,

    Try to use following code:

    function increament () {

    var value = Xrm.Page.getAttribute("new_revisionid").getValue();

    var isDirty = Xrm.Page.data.entity.getIsdirty();

    if (isDirty) {

    value++;

    Xrm.Page.getAttribute("new_revisionid").setValue(value);

    }

    }

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans