Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Javascript mscrm

Posted on by Microsoft Employee
function autoPop(executionContext) {
    var formContext = executionContext.getFormContext();
    var age = formContext.getAttribute("new_age").getValue();
if (age>=20 && age<=30) 
{
        formContext.getAttribute("new_agerange").setValue(0);
}
elseif(age>31 && age <=40)
{
      formContext.getAttribute("new_agerange").setValue(1);
}
else
{
    alert("smaller");
    Xrm.Page.data.entity.save();
}
 Can Anyone Please Explain this code

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Javascript mscrm

    Hi Krithika,
    In d365 microsoft has introduced formContext instead if Xrm.Page. Xrm.Page is being to be deprecated in next versions of CRM.

    Below is the same code used in earlier versions of CRM.

    function autoPop() {
    var age = Xrm.Page.getAttribute("new_age").getValue();
    if (age>=20 && age<=30)
    {
    Xrm.Page.getAttribute("new_agerange").setValue(0);
    }
    elseif(age>31 && age <=40)
    {
    Xrm.Page.getAttribute("new_agerange").setValue(1);
    }
    else
    {
    alert("smaller");
    Xrm.Page.data.entity.save();
    }
    }

    Regards,
    Sravan.J

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Javascript mscrm

    Hi Krithika,

    -----Please try not to create duplicate threads-----

    Regarding your query, the code gets the value of the field new_age and then sets the value 0 or 1 depending upon the age range i.e. if age is from 20 to 40 then set the value to 0 else if the value is from 31 and 40 then sets the value as 1. If none of the above range then saves the data.

    Could you please some details on what exactly you are trying to do as something is not quite right there.

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    javascript in crm
    function autoPop(executionContext) {
        var formContext = executionContext.getFormContext();
        var age = formContext.getAttribute("new_age").getValue();
    if (age>=20 && age<=30) 
    {
            formContext.getAttribute("new_agerange").setValue(0);
    }
    elseif(age>31 && age <=40)
    {
          formContext.getAttribute("new_agerange").setValue(1);
    }
    else
    {
        alert("smaller");
        Xrm.Page.data.entity.save();
    }
     

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans