Hi all,
This has my mind spinning. I need to set the lookup value of a new record via a web API. I currently do this for an option set using the below code to return the value based on a text match. I believe that the value I have to set for the lookup is ? a GUID rather than value as below.
So if the record to be created is in the Canditate entity and the lookup is in the Course entity how would I go about setting it. I have played with using EntityReference however no success to date.
if (!string.IsNullOrWhiteSpace(formValues.Get("Standard")))
{
string selectedValue = formValues.Get("Standard");
RetrieveAttributeRequest optionSetRequest = new RetrieveAttributeRequest();
optionSetRequest.EntityLogicalName = "Canditate";
optionSetRequest.LogicalName = "dev_standard";
optionSetRequest.RetrieveAsIfPublished = true;
RetrieveAttributeResponse optionSetResponse = (RetrieveAttributeResponse)service.Execute(optionSetRequest);
PicklistAttributeMetadata retrievedPicklistAttributeMetadata = (PicklistAttributeMetadata)optionSetResponse.AttributeMetadata;
OptionMetadata[] optionList = retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
int selectedOptionValue = 0;
foreach (OptionMetadata oMD in optionList)
{
if (string.Equals(oMD.Label.UserLocalizedLabel.Label, selectedValue, StringComparison.OrdinalIgnoreCase))
{
selectedOptionValue = oMD.Value.Value;
break;
}
}
if (selectedOptionValue == 0)
{
selectedOptionValue = 1;
}
target["dev_standard"] = new OptionSetValue(selectedOptionValue);
}
*This post is locked for comments
I have the same question (0)