1
I made a select to bring all entities that contain the "se_customdate" field as null. So far, no problem. However, now I need to assign the value of the variable "createdon" to the null fields, but I’m not able to progress in the code.
1: I thought to mount a foreach, where every entity returned as null, will pass through the loop and receive the value of createdon, was like this:
foreach(Entity etn in ec){  
               entity["se_customdate"] = "createdon";
            }
the foreach points the error:
"foreach statement cannot Operate on variables of type 'microsoft.xrm.sdk.entitycollection' because 'microsoft.xrm.sdk.entitycollection' does not contain a public Definition for 'Getenumerator'.
Follow code used by me all the way:
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 approaches/methods of resolution or even some light on how to proceed.
Gee, I get it! I was thinking I had to put the Getenumerator() somewhere on the lines of code, haha. So the second error was because I was passing the assignment as "secustomdate" += "createdon"; I did a search and found a guy who uses the assignment as Entity["se_customdate"] = "createdon"; Thank you very much, Gabriel!
– Mateus Binatti