locked
Custom Workflow for sending Remainder mail in MS CRM 2013/2015 online RRS feed

  • Question

  • Hi All,

    We have a requirement to send a remainder email before 5 days,3 days and on the same day of the M/TC date in lead form. To achieve this we tried using Custom Workflow. Below is the logic tried but in the highlighted line not able to retrieve the "M/TC date" value, this results in no output.

    Kindly suggest where we are going wrong or a best approach to do this.

    Parameters:

            [RequiredArgument]

            [Input("InputEntity")]

            [ReferenceTarget("lead")]

            public InArgument<EntityReference>inputlead { get; set; }

            [Output("TaskCreated")]

            [ReferenceTarget("task")]

            public OutArgument<EntityReference> taskCreated { get; set; }

    code:

                try  {

                Entity lead = (Entity)service.Retrieve("lead", context.PrimaryEntityId, new ColumnSet(newString[] { "new_mtcdate" })); //  (unable to retrieve the mtcdate)            

                      Guid leadId = this.inputlead.Get(executionContext).Id;

                    if(lead.Contains("new_mtcdate"))

                      {  DateTime date = DateTime.Now;

                          DateTime mtcdate = (DateTime)lead["new_mtcdate"];

                          TimeSpan elapsed = date.Subtract(mtcdate);

                          double days = elapsed.TotalDays;

                          Entity task = new Entity();

                          task.LogicalName = "task";

                          if (days == 5)

                          {task["subject"] = "Five days more for the Meeting";

                              task["regardingobjectid"]=new EntityReference("lead",leadId);

                               Guid taskId = service.Create(task);

                            this.taskCreated.Set(executionContext,new EntityReference("task", taskId));}

                          if (days == 3)

                          {task["subject"] = "Three days more for the Meeting";

                              task["regardingobjectid"]=new EntityReference("lead",leadId);

                               Guid taskId = service.Create(task);

                            this.taskCreated.Set(executionContext,new EntityReference("task", taskId));}

                          if (days == 0)

                          {task["subject"] = "Today you have Meeting";

                              task["regardingobjectid"]=new EntityReference("lead",leadId);

                               Guid taskId = service.Create(task);

                            this.taskCreated.Set(executionContext,new EntityReference("task", taskId));

                       }}}

               


    Regards, Rekha.J

    Tuesday, February 17, 2015 5:46 AM

All replies

  • Hi,

    Try with replacing

    Entity lead = service.Retrieve("lead", context.PrimaryEntityId, new ColumnSet(new string[] { "new_mtcdate" }));

    also make it confirm, you are getting EntityId.

    Also check  Link

    Tuesday, February 17, 2015 6:39 AM