Answered by:
Wait Condition in MS CRM 4.0 Workflow

Question
-
Hi,
Can any body help me,
I have a requirement related to the Wait condition in MS CRM 4.0 Workflow.
My requirement is i need to make the workflow to wait to the Next business day, and i need to check that the next business day is a working day or a holiday
if it is a working day i need run the workflow.
Note: I need to make the workflow to wait complete one day after Service Activity Created on irrespective of Time of created on starting from the 8am to 6pm, It should not consider the time but it should count the date only.
Regards,
Mohammad Riyazuddin
CRM Consultant.
Mohammad Riyazuddin CRM ConsultantWednesday, September 16, 2009 10:21 AM
Answers
-
Reset the IIS as well before you try to attach with appropriate process w3p.exe.
Also you can register your plugin in database and copy the .pdb file to the assembly directory. reset the iis and still you can debug your plugin from the server off-course. I always registered my plugins in database and can debug them. it doesn't have to be a Hard disk deployment for debugging.- Marked as answer by DavidJennawayMVP, Moderator Tuesday, October 27, 2009 11:51 AM
Tuesday, September 29, 2009 6:42 AM
All replies
-
Hi
you can do this
1) Create an attribute new_workflowrundate (datetime)
2) Register a plugin on post create, On Post Create Plugin of Service Activity update new_workflowrundate to the actual date on which the workflow should run. (you can easily check in your C# code when should be the next working day)
3) From MS CRM UI, create a non code workflow with wait condition.
Add a Wait Condition step and configure the step.a. Select Workflow from the entity list (first drop-down list).
b. Select Timeout from the attribute list (second drop-down list).
c. Select Equals from the operator list (third drop-down list).
d. Select new_workflowrundate from the Form Assistant
e. Save the configuration
5) Publish the above workflow.
for details, see this,
http://blogs.msdn.com/crm/archive/2008/01/08/part-1-happy-birthday-via-workflow-using-client-side-scripting.aspx- Proposed as answer by Muhammad Ali Khan Wednesday, September 16, 2009 12:38 PM
Wednesday, September 16, 2009 12:38 PM -
Hi Muhammad Ali,
Thanks for your support.
Please give me suggession on the below requirement, it will be a great help for me.
My requirement is i want to check that the next business day is a working day or not.
like i want to stop the workflow if the day is a Friday or Saturday because these two days are non working days.
Now i need to check weathere the next day is a Friday or saturday, if yes i need make the workflow to wait for two days(Fri and Sat)
Thanks and Regards,
Mohammad.Riyazuddin.
CRM Consultant
Mohammad Riyazuddin CRM ConsultantWednesday, September 23, 2009 4:48 AM -
Hi Riyaz
As i said,
1) Create an attribute new_workflowrundate (datetime)
2) Register a plugin on post create, On Post Create Plugin of Service Activity update new_workflowrundate to the actual date on which the workflow should run. (you can easily check in your C# code when should be the next working day)
In the above step once the Post create plugin is fired, you will write some logic to update the new_workflowrundate
It could be something like this
public void PostCreateServiceActivity : IPlugIn
{
public void Execute()
{
DateTime dt = DateTime.Now;
if(dt.DayOfWeek == DayOfWeek.Firday)
dt = dt.AddDays(2); // Add 2 Days to move to Sunday ( or 3 for Monday which is the working day)
else if(dt.DayOfWeek == DayOfWeek.Saturday)
dt = dt.AddDays(1); // Add 1 Days to move to Sunday (or 2 for Monday which is the working day)
// now update the new_workflowrundate = dt;
DynamicEntity entity = new DynamicEntity();
// write the rest of the code to update the new_workflowrundate = dt; attribute.
}
}
3) Create a workflow which will wait for the new_workflowrundate. Configure this workflow to run on the CHANGE of the new_workflowrundate.
From MS CRM UI, create a non code workflow with wait condition.
Add a Wait Condition step and configure the step.a. Select Workflow from the entity list (first drop-down list).
b. Select Timeout from the attribute list (second drop-down list).
c. Select Equals from the operator list (third drop-down list).
d. Select new_workflowrundate from the Form Assistant
e. Save the configuration
4) Configure this workflow to run on the change of the attribute new_workflowdate.
5) Publish the above workflow.
Explanation:-
Now once you create a service activity, a post create plugin will be fired, which will update the new_workflowdate to the date it should run the workflow.
Since the attribute new_workflowdate has been changed it will trigger the workflow, but the first condition of the workflow is to wait until new_workflowdate occurs, so the next step you can do after the wait conditions is to write your logic (which will happen once the wait is finished)
Wednesday, September 23, 2009 8:04 AM -
Hi,
you can also try to solve your issue with help of this WF activity http://www.jamesdowney.net/blog/post/Add-by-Business-Days-Workflow-Activity.aspxWednesday, September 23, 2009 10:25 AM -
Thank you very much for the answer, i was looking for the same solution.
I have successfully compiled the solution , but i am getting the error in registering the custom workflow.
The error is "Server was unable to process the request".
Please provide some information regarding registering the custom workflow.
Thanks and Regards,
Mohammad Riyazuddin.
CRM Consultant.
Mohammad Riyazuddin CRM ConsultantFriday, September 25, 2009 10:34 AM -
Hi Mohammad,
how are you trying to register the plugin? By custom code which uses the RegisterSolution-Message or with the PluginRegistration tool?Friday, September 25, 2009 11:20 AM -
I have tried with the register.xml file and Plugin registration tool, by both the methods iam getting the same error. Thanks and Regards, Mohammad.Riyazuddin, CRM Consultant
Mohammad Riyazuddin CRM ConsultantFriday, September 25, 2009 4:31 PM -
Hi Muhammad Ali,
As per your suggession
1). I have created a custom attribute new_workflowrundate (datetime).
2) Developed a Plugin on Post Create of Service Activity.
When i am trying to register the Plugin i am getting the error as "No Plugin have been selected from the list . Please select atleast one and try again".
The code for the plugin is.
class ActivityUpdate:IPlugin
{
public void Execute(IPluginExecutionContext context)
{//DynamicEntity target = (DynamicEntity)context.OutputParameters[ParameterName.Target];
DateTime dt = DateTime.Now;
if (dt.DayOfWeek == DayOfWeek.Sunday)
dt = dt.AddDays(3);
else
dt = dt.AddDays(1);//update the Service Activity
//Make sure we have an entity to work withif(context.InputParameters.Properties.Contains("Target")&& context.InputParameters.Properties["Target"] is DynamicEntity)
{
//Get the current service activity details
Guid activityID = new Guid(context.OutputParameters.Properties["id"].ToString());
ICrmService service = context.CreateCrmService(true);
//Obtain Guid
TargetRetrieveDynamic trd = new TargetRetrieveDynamic();
trd.EntityId = activityID;
trd.EntityName = "serviceappointment";//Retrieve Request
RetrieveRequest rr = new RetrieveRequest();
//Get the Columnset
rr.ColumnSet = new Microsoft.Crm.Sdk.Query.AllColumns();
rr.ReturnDynamicEntities = true;
rr.Target = trd;//Retrieve Response
RetrieveResponse rs = (RetrieveResponse)service.Execute(rr);
DynamicEntity entity = (DynamicEntity)rs.BusinessEntity;
(entity.Properties["new_workflowrundate"]) = dt;
service.Update(entity);
}
Please suggest if any thing is wrong with the plugin code.
Thanks and Regards,
Mohammad Riyazuddin
CRM Consultant.
Mohammad Riyazuddin CRM ConsultantSunday, September 27, 2009 3:07 PM -
in think you missed the public key word before the class. By default class access modifier is friendly means visible to only inside assembly and will not be accessible to other assembly like plugin registration tool.
public class ActivityUpdate:IPluginSunday, September 27, 2009 4:16 PM -
Hi Mohammad,
I just tried to register the assembly with the PluginRegistration tool. No problems here. Have you compiled the code yourself? Have you signed it?Monday, September 28, 2009 6:49 AM -
Hi Muhammad Ali,
Thank you very much for your support, Plugin got registered successfully, but at runtime it is generating an error "Value of type 'DateTime' is not supported.
Parameter name: value "
when i am updating the entity i am getting the error.
//Retrieve ResponseRetrieveResponse rs = (RetrieveResponse)service.Execute(rr);
DynamicEntity entity = (DynamicEntity)rs.BusinessEntity;
(entity.Properties["new_workflowrundate"]) = dt;
service.Update(entity);
Please suggest me the method by which we can update a Date Time attribute using plugin.
Thanks and Regards,
Mohammad Riyazuddin.
CRM Consultant
Mohammad Riyazuddin CRM ConsultantMonday, September 28, 2009 7:21 AM -
You have to use CrmDateTime, instead of DateTimeMonday, September 28, 2009 7:33 AM
-
Hi,
if i use CrmDateTime i am not getting the method to find the methods DayOfWeek and AddDays
CrmDateTime dt = CrmDateTime.Now;
public class ActivityUpdate:IPlugin
{
public void Execute(IPluginExecutionContext context)
{//DynamicEntity target = (DynamicEntity)context.OutputParameters[ParameterName.Target];
DateTime dt = DateTime.Now;
if (dt.DayOfWeek == DayOfWeek.Sunday)
dt = dt.AddDays(3);
else
dt = dt.AddDays(1);//update the Service Activity
//Make sure we have an entity to work withif(context.InputParameters.Properties.Contains("Target")&& context.InputParameters.Properties["Target"] is DynamicEntity)
{
//Get the current service activity details
Guid activityID = new Guid(context.OutputParameters.Properties["id"].ToString());
ICrmService service = context.CreateCrmService(true);
//Obtain Guid
TargetRetrieveDynamic trd = new TargetRetrieveDynamic();
trd.EntityId = activityID;
trd.EntityName = "serviceappointment";//Retrieve Request
RetrieveRequest rr = new RetrieveRequest();
//Get the Columnset
rr.ColumnSet = new Microsoft.Crm.Sdk.Query.AllColumns();
rr.ReturnDynamicEntities = true;
rr.Target = trd;//Retrieve Response
RetrieveResponse rs = (RetrieveResponse)service.Execute(rr);
DynamicEntity entity = (DynamicEntity)rs.BusinessEntity;
(entity.Properties["new_workflowrundate"]) = dt;
service.Update(entity);
}Thanks and Regards,
Mohammad Riyazuddin.
CRM Consultant
Mohammad Riyazuddin CRM ConsultantMonday, September 28, 2009 7:50 AM -
Use the properties UserTime or UniversalTime of the CrmDateTime class to access its DateTime value (see http://msdn.microsoft.com/en-us/library/bb930191.aspx)Monday, September 28, 2009 7:53 AM
-
update the datetime property like this
DynamicEntity entity = (DynamicEntity)rs.BusinessEntity;
CrmDateTime crmDate = new CrmDateTime();
crmDate.Value = dt.ToString("s"); // s = "UTC format"(entity.Properties["new_workflowrundate"]) = crmDate;
service.Update(entity);Monday, September 28, 2009 8:19 AM -
Hi Muhammad Ali,
I am very much thankfull for your support, as i am new to the CRM.
I have developed PostCreate plugin and a custom attribute new_workflowrundate, and deployed it to the CRM, deployment is successfull.
But Plugin is not firing. Below is the Plugin Code, Please if you can suggest me the problem of the plugin it will be a great help for me.
using
System;
using
System.Collections.Generic;
using
System.Text;
using
Microsoft.Crm.Sdk;
using
Microsoft.Crm.SdkTypeProxy;
namespace
RunWorkflowPlugin
{
public class ActivityUpdate:IPlugin
{
public void Execute(IPluginExecutionContext context)
{
DateTime dt = DateTime.Now;
if (dt.DayOfWeek == DayOfWeek.Thursday)
dt = dt.AddDays(3);
else
dt = dt.AddDays(1);
//update the Service Activity
//Make sure we have an entity to work with
if (context.InputParameters.Properties.Contains("Target") && context.InputParameters.Properties["Target"] is DynamicEntity)
{
//Get the current service activity details
Guid activityID = new Guid(context.OutputParameters.Properties["id"].ToString());
ICrmService service = context.CreateCrmService(true);
//Obtain Guid
TargetRetrieveDynamic trd = new TargetRetrieveDynamic();
trd.EntityId = activityID;
trd.EntityName =
"serviceappointment";
//Retrieve Request
RetrieveRequest rr = new RetrieveRequest();
//Get the Columnset
rr.ColumnSet =
new Microsoft.Crm.Sdk.Query.AllColumns();
rr.ReturnDynamicEntities =
true;
rr.Target = trd;
//Retrieve Response
RetrieveResponse rs = (RetrieveResponse)service.Execute(rr);
DynamicEntity entity = (DynamicEntity)rs.BusinessEntity;
CrmDateTime crmDate = new CrmDateTime();
crmDate.Value = dt.ToString(
"s"); // s = "UTC format"
CrmDateTimeProperty dtp = new CrmDateTimeProperty();
dtp.Name =
"new_workflowrundate";
dtp.Value = crmDate;
entity.Properties.Add(dtp);
//(entity.Properties["new_workflowrundate"]) = crmDate;
//(entity.Properties["new_workorder"]) = "workorder123";
service.Update(entity);
}
}
}
}
Mohammad.Riyazuddin.
CRM Consultant
Mohammad Riyazuddin CRM ConsultantTuesday, September 29, 2009 5:24 AM -
Hi,
Not firing means, the code is not executed at all?
Which entity you registered your plugin? serviceappointment?
Also did you try to copy the .pdf file to the assembly directory and try to debug the w3p.exe process?Tuesday, September 29, 2009 6:05 AM -
Hi Muhammad Ali,
I have registered plugin for post create of serviceappointme entity. and I have tried to debug by deploying it to Disk and copied the dll and pdb files to the server\bin\assembly folder of the CRM installation.
Eventhough i could not able to debug.
Thanks and Regards,
Mohammad Riyazuddin.
CRM Consultant
Mohammad Riyazuddin CRM ConsultantTuesday, September 29, 2009 6:29 AM -
Reset the IIS as well before you try to attach with appropriate process w3p.exe.
Also you can register your plugin in database and copy the .pdb file to the assembly directory. reset the iis and still you can debug your plugin from the server off-course. I always registered my plugins in database and can debug them. it doesn't have to be a Hard disk deployment for debugging.- Marked as answer by DavidJennawayMVP, Moderator Tuesday, October 27, 2009 11:51 AM
Tuesday, September 29, 2009 6:42 AM