RE: How to retrieve optionset value or optionset selected text using plugin?
//my code:i want to update parent record when the child records are updated..
//i used post-operation and the message is on update of child entity("tj_patient")
//my parent entity name is "tj_doctor"
Entity records = (Entity)context.InputParameters["Target"];
if (records.LogicalName == "tj_patient")
{
int statuscount = 0;
int status;
Guid doctorid;
QueryExpression query = new QueryExpression();
query.EntityName = records.LogicalName;
query.ColumnSet = new ColumnSet("tj_name","tj_status");
EntityCollection collection = service.RetrieveMultiple(query);
foreach (Entity results in collection.Entities)
{
status = ((OptionSetValue)results.Attributes["tj_status"]).Value;
EntityReference reference = (EntityReference)records.Attributes["tj_doctor"];
doctorid = reference.Id;
ColumnSet parentcolumns = new ColumnSet("tj_status");
Entity parentrecord = service.Retrieve("tj_doctor", doctorid, parentcolumns);
if (status == 212200000)
{
statuscount++;
if (statuscount >= 4)
{
parentrecord.Attributes["tj_status"] = new OptionSetValue(212200000);
service.Update(parentrecord);
}
}
}
}