Hi All,
I have registered this code on create of contact entity. I am retrieving data from Auto Number Entity but not able to update in auto number entity. Below is my code. Please help
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
if (context.Depth == 1)
{
int NumberFormat=0;
Entity enity = (Entity)context.InputParameters["Target"];
var entityLogicalName = enity.LogicalName;
Entity entityAutoNumber = new Entity("new_autonumbering");
//entityAutoNumber.Id=""
string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='new_autonumbering'>
<attribute name='new_autonumberingid' />
<attribute name='new_name' />
<attribute name='new_numberformat' />
<filter type='and'>
<condition attribute='new_name' operator='eq' value='" + entityLogicalName + @"' />
</filter>
</entity>
</fetch>";
EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetchXML));
if (result.Entities.Count == 1)
{
foreach (var c in result.Entities)
{
var LatesAutoNumberValue = c.Attributes["new_numberformat"];
enity["new_contactid"] = Convert.ToString(LatesAutoNumberValue);
NumberFormat = Convert.ToInt32(c.Attributes["new_numberformat"]);
}
}
else
{
throw new InvalidPluginExecutionException("Auto Number increment is not configured for this Entity ot it has multiple record in Auto Number ");
}
NumberFormat = NumberFormat+1;
entityAutoNumber["new_numberformat"] = NumberFormat;
//service.Update(entityAutoNumber);
service.Update(enity);
}
}
*This post is locked for comments