Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

I a trying a very simple stuff. getting value of a lookup field in My CRM console application

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi Everyone,

How are you .

am new to Microsoft language .currently  am working on console application which will have to retrieve lookup field  value in my console .

i don't  syntax, how to retrieve value from lookup field.

entity name is :kcd_creditrisk

field name id :kcd_billid

Thanks.

Venkat

  

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I a trying a very simple stuff. getting value of a lookup field in My CRM console application

    below code returning  bill id value ,whenever there is a record in entity for provided guid.

    Entity creditrisk = svc.Retrieve("kcd_creditrisk", creditriskguid, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));--->

    i need some value from expression ,when there is no records for specified guid,however i can create records.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I a trying a very simple stuff. getting value of a lookup field in My CRM console application

    Hi venkataramana,

    it is not clear what is the problem, i understood you want to deal with null values (record not found); in this case proceed as follows:

    Entity creditrisk = svc.Retrieve("kcd_creditrisk", creditriskguid, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
    string billid = null;
    if (creditrisk != null)
    {
        billid = creditrisk.GetAttributeValue<string>("kcd_billid");
    }
    else
    {
        // do something
    }


    If i'm wrong, please try to explain your issue better.

    Looking forward to hearing from you.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: I a trying a very simple stuff. getting value of a lookup field in My CRM console application

    This is in reference to the below line of code-

     var target = service.Retrieve(entityName, entityId, new ColumnSet(true));

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: I a trying a very simple stuff. getting value of a lookup field in My CRM console application

    It is just a variable to store the Entity object returned from the service.retrieve

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I a trying a very simple stuff. getting value of a lookup field in My CRM console application

    what is mean by "target"

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: I a trying a very simple stuff. getting value of a lookup field in My CRM console application

    Hi Venkat,

    Are you talking about the service.Retrieve? If yes then it will throw error if there are no records for the id you have passed.

    How to check if the record exists or not is already answered in your below thread. If you are still facing issues then please continue on the below thread.

    community.dynamics.com/.../257142

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I a trying a very simple stuff. getting value of a lookup field in My CRM console application

    Hi Francesco,

    How are you

    below code is working  when there is are records in entity,otherwise throwing does not exist exception.

    if records does't exist means i should get empty billid value to create a record.-->not working for create case

    if records already exist it returning billid and updating.--->working for update case

    Entity creditrisk1 = service.Retrieve("kcd_creditrisk", id, new Microsoft.Xrm.Sdk.Query.ColumnSet("kcd_billid"));

                                   string crbillid = creditrisk1.GetAttributeValue<string>("kcd_billid");

    Venkat

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I a trying a very simple stuff. getting value of a lookup field in My CRM console application

    returning all ways empty.

    string crbillid = creditrisk1.Contains("kcd_billid") ? creditrisk1["kcd_billid"].ToString() : string.Empty;

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I a trying a very simple stuff. getting value of a lookup field in My CRM console application

    Hi venkataramana,

    if you solved the problem thanks to an answer, please mark it as verified to encourage the community to provide more and more a better support. Then, open a new thread for the new issue specifying the new subject, to help who will need to solve a similiar issue in the future. Thank you. Francesco

    If you found the answer helpful, please mark as Verified 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: I a trying a very simple stuff. getting value of a lookup field in My CRM console application

    now my requirement  from customer..

    i have  bill id from third part system.

    i wanted to verify bill id is  exist or not in entity(kcd_creditrisk) ,field name(kcd_billingid).

    please help me .

    Venkat

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,399 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans