I have written a custom logic in post create of custom entity(Entity A), in which i'm creating few child records(Entity B) and associating them to Entity A using executemultiplerequest(CreateRequest) . I get a fault in the response, saying "Entity A with guid doesn't exists". But the same logic will work if I use IOrganizationService.Create method. Please help me in knowing why executemultiplerequest doesn't work.
Below is the code:
EntityCollection itemResourceCollection = RetrieveItemResources(itemResources, xrmService);
var executeMultipleRequest = new ExecuteMultipleRequest
{
Settings = new ExecuteMultipleSettings
{
ContinueOnError = false,
ReturnResponses = true
},
Requests = new OrganizationRequestCollection()
};
foreach (var itemResource in itemResourceCollection.Entities)
{
var createRequest = new CreateRequest
{
Target = itemResource
};
executeMultipleRequest.Requests.Add(createRequest);
}
var response = (ExecuteMultipleResponse)xrmService.Execute(executeMultipleRequest);
public virtual EntityCollection RetrieveItemResources(List<EntityItemResource> itemResources, XrmService xrmService)
{
var itemResourceCollection = new EntityCollection();
foreach (var itemResource in itemResources)
{
var entityItemResource = new Entity("new_resource");
entityItemResource.Attributes.Add("new_jobcardid", this.ToEntityReference());
//"this" is the target entity
foreach (var attributes in itemResource.ItemResourceFields)
{
if (attributes.Type == Constants.EntityReference)
{
var entityReference = RetrieveEntityReferenceForLookup(attributes.LookUpEntity, attributes.SearchField, attributes.AttributeValue, xrmService);
entityItemResource.Attributes.Add(attributes.AttributeName, entityReference);
}
else if (attributes.Type == Constants.optionset)
{
entityItemResource.Attributes.Add(attributes.AttributeName, new OptionSetValue(Convert.ToInt32(attributes.AttributeValue)));
}
else if (attributes.Type == Constants.money)
{
entityItemResource.Attributes.Add(attributes.AttributeName, new Money(Convert.ToDecimal(attributes.AttributeValue)));
}
else if (attributes.Type == Constants.WholeNumber)
{
entityItemResource[attributes.AttributeName] = Convert.ToInt32(attributes.AttributeValue);
}
else
{
entityItemResource[attributes.AttributeName] = attributes.AttributeValue;
}
}
itemResourceCollection.Entities.AddRange(entityItemResource);
}
return itemResourceCollection;
}
*This post is locked for comments
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,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156