Skip to main content

Notifications

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

  • meenoo Profile Picture
    7,316 on at
    RE: Setting a lookup field value

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

  • meenoo Profile Picture
    7,316 on at
    RE: Setting a lookup field value

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


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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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 54

#3
dkrishna Profile Picture

dkrishna 6

Featured topics

Product updates

Dynamics 365 release plans