How to get id lookup field in target entity ?, I use Plugin c#
Thanks,
*This post is locked for comments
How to get id lookup field in target entity ?, I use Plugin c#
Thanks,
*This post is locked for comments
without adding this?
else if (targetEntity.Attributes.Contains("swo_projectsurveyid") && targetEntity.Attributes["swo_projectsurveyid"] == null)
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")
Hi Iswarya,
What if I want to read projectsurveyid is null?
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...
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;
}
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.
André Arnaud de Cal...
292,489
Super User 2025 Season 1
Martin Dráb
231,305
Most Valuable Professional
nmaenpaa
101,156