Hi Everyone,
Getting an index out of range error when i run a custom workflow.
I've debugged and it breaks on the line highlighted in red. Any ideas why its breaking? do i need to specify the amount of elements in my entity collection?
try
{
DynamicUrlParser dup = new DynamicUrlParser(dynamicRecordURL);
string EntityLogicalName = dup.GetEntityLogicalName(service);
Entity targetEntity = service.Retrieve(EntityLogicalName, dup.Id, new ColumnSet(true));
bool changed = false;
if (stringValue != null)
{
string fetchXMLOptionSet = @"<fetch>
<entity name='stringmap' >
<attribute name='value' />
<attribute name='attributevalue' />
<filter>
<condition attribute='objecttypecodename' operator='eq' value='{0}' />
<condition attribute='attributename' operator='eq' value='{1}' />
<condition attribute='value' operator='eq' value='{2}' />
</filter>
</entity>
</fetch>";
fetchXMLOptionSet = String.Format(fetchXMLOptionSet, EntityLogicalName, fieldLogicalName, stringValue);
var query = new FetchExpression(fetchXMLOptionSet);
EntityCollection OptionsetValues = service.RetrieveMultiple(query);
Entity OSV = OptionsetValues[0];
targetEntity[fieldLogicalName] = new OptionSetValue(OSV.GetAttributeValue<int>("attributevalue"));
changed = true;