hi all,
please suggest me how to retrieve optionset value or optionset selected text using plugin.
i tried below code but not working,throwing an error "given key was not present in dictionary"
foreach (Entity results in collection.Entities)
{
string status = results .FormattedValues["tj_status"].ToString();
int status = ((OptionSetValue)results.Attributes["tj_status"]).Value;
}
Thanks!
*This post is locked for comments
Try going to the advanced find and search for all records where tj_status is empty. If you get anything in the results, those are the records on which your code is failing.
You likely need to add a condition (somewhere)
if(results.Contains("tj_status")){
}
//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);
}
}
}
}
Do you get error for both lines or just one?
Hi Tejagupta,
If your optionset attribute didn't change in form (or via SDK code), you can not find this attribute in your plugin.
For this, you have to use "entity / plugin images", you can easly register images from Plugin Registration Tool. You can find more details on https://msdn.microsoft.com/en-gb/library/gg309673.aspx
Hi,
which line is it failing on? Technically, that's exactly how you are supposed to be doing that.. but, on the other hand, if a value has not been selected for a particular record, you'll get that error. So you may want to check, first, if the attribute is there (for each record)
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,113 Super User 2024 Season 2
Martin Dráb 229,918 Most Valuable Professional
nmaenpaa 101,156