There is a method named ExecuteWorkflowRequest using which we can execute our workflow programmatically. We had a requirement to find all the opportunities which haven’t been modified for past 30 days and to decrease their probability attribute value by 10.
Now the thing over here was that there wasn’t any specific event against which we could have fired the above workflow. So we thought of writing an application which than we could scheduled, which will periodically run the above workflow
This is how we implemeneted it within a windows application
private void Form1_Load(object sender, EventArgs e){
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = “organizationName”;
//0 – AD
//1 – Passport
//2 – Form Authentication
token.AuthenticationType = 0;
CrmService crmService = new CrmService();
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
crmService.CrmAuthenticationTokenValue = token;
crmService.Url = “http://servername:port/mscrmservices/2007/crmservice.asmx”;
try{
// Create an ExecuteWorkflow request.
ExecuteWorkflowRequest request = new ExecuteWorkflowRequest();
//Assign the ID of the workflow you want to execute to the request.
// use this query to get the id select parentworkflowid,name,* from dbo.Workflow
// id is the parentworkflowid
request.WorkflowId = new Guid(“21B9528D-D13D-4B93-9F91-FA7468D3C82C”);
// We want to run it against all the opportunity which are in open state
ArrayList OpportunityGuids = GetOpportunityGuids(crmService);
foreach (String oppGuid in OpportunityGuids){
//Assign the ID of the entity to execute the workflow on to the request.
request.EntityId = new Guid(oppGuid);
ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)crmService.Execute(request);}
// Execute the workflow. }
catch (SoapException ex){
// write in log}
catch (Exception ex){
// write in log} }
private ArrayList GetOpportunityGuids(CrmService crmService){
// using QueryByAttribute to retrieve all the opportunity having statuscode as 1 i.e. Open
QueryByAttribute myOppQuery = new QueryByAttribute();
myOppQuery.Attributes = new String[] { “statuscode” };
myOppQuery.Values = new String[] {“1”};
ColumnSet myCols = new ColumnSet();
myOppQuery.ColumnSet = myCols;
myOppQuery.EntityName = EntityName.opportunity.ToString();
WindowsFormsApplication2.CrmSdk.BusinessEntityCollection myOppCollection= crmService.RetrieveMultiple(myOppQuery);
ArrayList opportunityGuids = new ArrayList();
foreach (WindowsFormsApplication2.CrmSdk.BusinessEntity opp in myOppCollection.BusinessEntities ){
opportunity myOpp = (opportunity)opp;
opportunityGuids.Add(myOpp.opportunityid.Value.ToString()); }
return opportunityGuids;
}
Bye ..
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.

Thank you for an excelent article.
I need the oposit of what you have done.
I have a need to programaticaly cancele a workflow that is in wait state for an opprtunity from an update plug-in. Do you know how do go about this?
avner
LikeLike
hi Nishant
actually i m doing some functionality about the feedback form in MS CRM
i need feedback form in Event management it is used for attendee’s feedback, a link is send through mail, and attendee’s can enter the feedback from the feedback form and that data is populate in MS CRM Feedback entity. i made a entity of same field those are in feedback form, i want that whn all the entity is filled in form and then attendee submit the form all the data attendee enter populate in MS CRM.
is this information is sufficent to u or u required more, i hope u will soon rply to my mail. i m in very tense stage plz help me out.
thanks
manish
LikeLike
my email id is ermanish tyagi@gmail.com
please send the help as soon as possible.
LikeLike
hi Nishant
yes u r right,
i have made the feedback form in ASP.NET name feedback.aspx, yes user can be internal or external both have to enter the feedback about the event from the link that they recieved from mail.
now the problem is how to integrate it
feild information are:
name:
email:
feedback related to:
comments:
rate the event:
link are sending to the list of user, or those how attend the event, via mail.
i have already create the custom entity in MS CRM named feedback and a feedback form and the fields are same as above in both. is it sufficent.
more over if u send feedback back form or how to integrate it in mS CRM code i will use that only. plz rply as soon as possible
thanks
manish
LikeLike
hi
look have u ever book your movies ticket from any site, that seating arrangement i hope u now under stand wht i try to do by finding the above attachments.
and for more details please have a look on site
http://www.bookmyshow.com/BuyTickets.aspx?srid=DELHI&eid=ET00002496&cid=&did=20090331&ety=MT
i think this is more than enough plz help me
thanks
abhi
LikeLike
Thx a lot.
LikeLike
If you are going for most excellent contents like myself, simply pay a
visit this web site everyday for the reason that it presents feature contents, thanks
LikeLike
I am regular visitor, how are you everybody? This paragraph posted at
this website is genuinely good.
LikeLike