I made a select to bring all the entities which contain the field "se_customdate" to null. Until then, no problem. However, I now need to assign the value of the "createdon" variable to the null fields, but I'm not getting any progress in the code.
1: I thought about putting a foreach, where every entity returned as null, will pass through the loop and will receive the value of createdon, it looks like this:
foreach(Entity etn in ec){
entity["se_customdate"] = "createdon";
}
foreach points to error:
"foreach statement can not operate on variables of type 'microsoft.xrm.sdk.entitycollection' because 'microsoft.xrm.sdk.entitycollection' does not contain a public definition for 'GetEnumerator'.
Here is the code I used all along:
public class PreencheCampoDataHistorico : CodeActivity
{
private string _activityName = "Preencher Campo de Data Historico";
protected override void Execute(CodeActivityContext executionContext)
{
ITracingService tracingService = executionContext.GetExtension<ITracingService>();
if (tracingService == null)
{
throw new InvalidPluginExecutionException("Failed to retrieve tracing service.");
}
tracingService.Trace("Entered " + _activityName + ".Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}",
executionContext.ActivityInstanceId,
executionContext.WorkflowInstanceId);
// Create the context
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
if (context == null)
{
throw new InvalidPluginExecutionException("Failed to retrieve workflow context.");
}
tracingService.Trace(_activityName + ".Execute(), Correlation Id: {0}, Initiating User: {1}",
context.CorrelationId,
context.InitiatingUserId);
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
Entity entity = new Entity("se_historicodelicenciamento");
ColumnSet attributes = new ColumnSet(new string[] { "se_customdate","createdon" });
QueryExpression query = new QueryExpression
{
EntityName = entity.LogicalName,
ColumnSet = new ColumnSet (new string[] {"name","se_customdate","createdon"}),
Criteria =
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = "se_customdatehistory",
Operator = ConditionOperator.Equal,
Values = {String.Empty}
}
}
}
};
EntityCollection ec = service.RetrieveMultiple(query);
foreach(Entity etn in ec){
entity["se_customdate"] = "createdon";
}
I ask for ideas, new ways of approach / methods of resolution or even some light on how to proceed.