Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get id lookup in target entity

(0) ShareShare
ReportReport
Posted on by 403

How to get id lookup field in target entity ?, I use Plugin c#

Thanks,

4617.get-guid.PNG

*This post is locked for comments

  • Ferdiansah Profile Picture
    Ferdiansah 403 on at
    RE: Get id lookup in target entity

    without adding this?

    else if (targetEntity.Attributes.Contains("swo_projectsurveyid") && targetEntity.Attributes["swo_projectsurveyid"] == null)

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Get id lookup in target entity

    Hi,

    You can use the below statment to check if it si null or not

    // Returns false if it is null

    entity.Attributes.Contains("new_projectsurveyid")

  • Ferdiansah Profile Picture
    Ferdiansah 403 on at
    RE: Get id lookup in target entity

    Hi Iswarya,

    What if I want to read projectsurveyid is null?

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Get id lookup in target entity

    This also depends in what step and message you are trying to retrieve the attribute from.

    You need to get the Project Survey Id field of the Activation Request entity.

    In general there are two ways to get the entity object.

    The first is to use the Target Parameter of the Execution Context -> Input Parameters:

    Entity activationRequest = (Entity)context.InputParameters("Target");

    The second is using the Organization Service Retrieve method passing the entity name, entity id and columns to be retrieved:

    Entity activationRequest = service.Retrieve(entityName, entityId, new ColumnSet(true));

    // The above line of code will retrieve all columns. You can filter the columns to retrieve by changing the last parameter of the Retrieve function call.

    Once you have the entity object, you can get the parameter by calling:

    Guid projectSurveyId = ((EntityReference)activationRequest.Attributes[attributeName]).Id;

    Hope this helps...

  • Verified answer
    Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: Get id lookup in target entity

    Hi,

    try this

       Entity entity = (Entity)context.InputParameters["Target"];

                           if (entity.LogicalName != "new_activationrequest")

                           {

                               return;

                           }

                                   if (entity.Attributes.Contains("new_projectsurveyid") && entity.Attributes["new_projectsurveyid"] != null)

                               {

                                  Guid ProjectSurvey = ((EntityReference)entity.Attributes["new_projectsurveyid"]).Id;

                               }

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Get id lookup in target entity

    Hi,

    Check the below code. It retrieves the Primary Contact look field of an account entity. You can change the schema name as per your system.

                    var primaryContact = (EntityReference)target["primarycontactid"];

    Full Console Code

    ================

    public void RetrievePrimaryContactId()

          {

              // Set the credentials

              ClientCredentials credential = new ClientCredentials();

              credential.UserName.UserName = "username@testorg.onmicrosoft.com";

              credential.UserName.Password = "password";

              // Set the org url

              var organizationURI = "testorg.crm6.dynamics.com/.../Organization.svc";

              using (service = new OrganizationServiceProxy(new Uri(organizationURI), null, credential, null))

              {

                  var entityId = new Guid("AF327C64-98BE-E711-8129-E0071B67EC91");

                  var entityName = "account";

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

                  // Check if the Primary Context exists

                  if (target.Contains("primarycontactid"))

                  {

                      // Get the primary contact entity reference

                      var primaryContact = (EntityReference)target["primarycontactid"];

                      // Get the GUID of primary contact

                      var contactId = primaryContact.Id;

                  }

              }

          }

    ================

    Hope 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

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,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans