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)

Setting a lookup field value

(0) ShareShare
ReportReport
Posted on by 7,316

Hi,

I am setting up a lookup field value which is retrieved from another lookup field value on same entity form.

Here is the script:

function sample()
{
debugger;
var ExistingCase = Xrm.Page.data.entity.attributes.get("new_userteam");

if (ExistingCase.getValue() != null) {
   var ExistingCaseGUID = ExistingCase.getValue()[0].id;
    var ExistingCaseName = ExistingCase.getValue()[0].name;

var lookupValue=new Array();
lookupValue[0] = new Object();
lookupValue[0].id=ExistingCaseGUID;
lookupValue[0].name=ExistingCaseName;
lookupValue[0].entityType="incident";
Xrm.Page.getAttribute("new_lapcounty").setValue(lookupValue);
}

}

I debug the script but I don't see anything wrong but value is not getting set up!
Can someone please let me know what I am doing wrong? Thanks.

*This post is locked for comments

I have the same question (0)
  • meenoo Profile Picture
    7,316 on at

    Thanks Guido. You are right. They are not pointing to incident entity.

    I changed it to get the typename as well. But it still not updating the lookup field!

    function sample()
    {
    debugger;
    var ExistingCase = Xrm.Page.data.entity.attributes.get("new_userteam");
    
    if (ExistingCase.getValue() != null) {
       var ExistingCaseGUID = ExistingCase.getValue()[0].id;
        var ExistingCaseName = ExistingCase.getValue()[0].name;
    var ExistingCaseType = ExistingCase.getValue()[0].typename;
    
    
    var lookupValue=new Array();
    lookupValue[0] = new Object();
    lookupValue[0].id=ExistingCaseGUID;
    lookupValue[0].name=ExistingCaseName;
    lookupValue[0].typename=ExistingCaseType;
    Xrm.Page.getAttribute("new_lapcounty").setValue(lookupValue);
    }
    
    }
    


  • meenoo Profile Picture
    7,316 on at

    Awesome. Thank you so much. It worked. Got a clear understanding today of how lookup fields work. :)

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