web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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

I have the same question (0)
  • Verified answer
    Rawish Kumar Profile Picture
    13,758 on at

    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);

  • Verified answer
    Community Member Profile Picture
    on at

    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
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Nirpendra,

    Change num.setValue(pre_classfees);

    to

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

  • Community Member Profile Picture
    on at

    your code works....

    thank you

  • Community Member Profile Picture
    on at

    thank u all of u

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Nirpendra,

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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans