Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

set field value depends on lookup value

(0) ShareShare
ReportReport
Posted on by

Hi Guys,

            I have a two entities working hour and class. In working hour I have a look up of class entity which name class lookup. I want to get class entity field value which name fees and set in the working hour field which name pay.

This pay field value changes according to class look field.

below my code :

function good(){
console.log("1");
var lookupGuid = Xrm.Page.data.entity.attributes.get("pre_classlookup").getValue()[0].id.slice(1,-1);
alert(lookupGuid);
var num=Xrm.Page.data.entity.attributes.get("pre_pay").getValue();
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/pre_classes("+lookupGuid+")?$select=pre_classfees", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var pre_classfees = result["pre_classfees"];
alert(pre_classfees);
if(num== null)
{
alert("null");
}
else if(num!=null)
{
alert(num);
}
num.setValue(pre_classfees);
alert("xx");
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}

my code breaks on num.setValue(pre_classfees);

please guide me because I am fresher in Javascript

Thanks

*This post is locked for comments

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: set field value depends on lookup value

    Hi Nirpendra,

    Please mark the suggestion as helpful/ answer and close the thread. This may help someone else looking for the same/ similar issue.

  • Community Member Profile Picture
    on at
    RE: set field value depends on lookup value

    thank u all of u

  • Community Member Profile Picture
    on at
    RE: set field value depends on lookup value

    your code works....

    thank you

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: set field value depends on lookup value

    Hi Nirpendra,

    Change num.setValue(pre_classfees);

    to

    Xrm.Page.data.entity.attributes.get("pre_pay").setValue(pre_classfees);

  • Verified answer
    Community Member Profile Picture
    on at
    RE: set field value depends on lookup value

    Hi,

    you should write :

    var num=Xrm.Page.data.entity.attributes.get("pre_pay");

    then in your ifs do num.getValue()

    and finally num.setValue will work.

  • Verified answer
    Rawish Kumar Profile Picture
    13,758 on at
    RE: set field value depends on lookup value

    hey nirpendra,

    it will fail because in num you have get value method too. so practically  - "num" will be null. hence you cant set value to it. CRM will not recognize what it is.

    to set the value you have to again say :

    Xrm.Page.getAttribute(“pre_prepay”).setValue(pre_classfees);

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

🌸 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…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans