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)

How to get Lookup Details while retrieve or fetch record using XrmServiceToolkit Library

(1) ShareShare
ReportReport
Posted on by 314

Hello All,

 I have retrieved one  Entity record using XrmServiceToolkit. In this entity there is a lookup field(mentioned in filter) also get. Now i want to access particular properties of this Lookup like name, id, entityType ? How can i get all these? basically i think  we use the following code to execute the query for Rest: 

var result = XrmServiceToolkit.Soap.Retrieve(EntityName,EntityId,col);

and to Retrieve any field value we write the following code,
var x = result.attributes['fieldname'].value; 

here, x can store normal values like single line, whole number etc but in my case the field is lookup
and i want to access the lookup properties?? If i simply write alert(x) then it shows the error because
x is referring to Another Record, and I want to simply get the name of that record??


*This post is locked for comments

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

    Hi Ishan,

    This is WebApi , so here is how you can achieve it :

    http://himbap.com/blog/?p=2077

    mark my suggestion as verified if helpful.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Helo Ishan ,

    Try with this . Hope this helps -

        var cols = ["new_textfield", "primarycontactid"];
        var resultXml = XrmServiceToolkit.Soap.Retrieve(EntityName, EntityId, cols);
        
       // Get Lookup Value 
    
        if (resultXml != null && resultXml.attributes['primarycontactid'] != null) {
            var lookupValue = new Array();
            lookupValue[0] = new Object();
            lookupValue[0].id = resultXml.attributes['primarycontactid'].id;
            lookupValue[0].name = resultXml.attributes['primarycontactid'].name;
            lookupValue[0].entityType = resultXml.attributes['primarycontactid'].logicalName;
            Xrm.Page.data.entity.attributes.get("parentcontactid").setValue(lookupValue);
        }
        else
            Xrm.Page.data.entity.attributes.get("parentcontactid").setValue(null);


  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Ishan,

    I am not sure  which version of CRM you are using and why you are still depends on XrmServiceToolkit ?

    Microsoft introduce XRM method WebApi which uses  OData V4  and as well as you can retrieve using rest API using XMLHttpRequest which was already shared by  Rawish .

    So you don't need to depends on external reference or SDK. So start using  XRM method  WebAPI or  rest API using  XMLHttpRequest .

    Please have a look below reference -

    docs.microsoft.com/.../xrm-webapi

    msdn.microsoft.com/.../gg334279.aspx

    To create REST API using tool you can download the CRM rest builder and import the solution in your CRM instance which will give you a button in solution area Ribbon. You can easily create your XMLHttpRequest .

    github.com/.../CRMRESTBuilder

    Hoe this helps

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