locked
Running Workflow from custom page RRS feed

  • Question

  • Hi,

    i need to develop custom asp page which would have 2 buttons and clicking of any of them would run a different workflow. Is this sollution posible, is there a way to run any workflow on any object using CRM SDK passing required parameters? If yes, which how this could be done and, i would be grateful for short example or any link with similar problem.
    Another thing, i would like to display my custom page in iframe, is there a way to pass parameters to iframe and read them in custom page? I was thinking to pass them for example in URL parameter to iframe and read them using c# code.

    Thanks for all help,

    Chevie
    Tuesday, December 29, 2009 9:49 AM

Answers

  • Hi Chevie,

    You can run a workflow from code using the CRM SDK.

    The sample code below (taken from the CRM SDK) demonstrates how you would do this.



    [C#]
    // Set up the CRM Service.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
    token.AuthenticationType = 0;
    token.OrganizationName = "AdventureWorksCycle";

    CrmService service = new CrmService();
    service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
    service.CrmAuthenticationTokenValue = token;
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;

    // Create an ExecuteWorkflow request.
    ExecuteWorkflowRequest request = new ExecuteWorkflowRequest();

    //Assign the ID of the workflow you want to execute to the request.        
    request.WorkflowId = new Guid("b050f053-6968-dc11-bb3a-0003ffbad37a");

    //Assign the ID of the entity to execute the workflow on to the request.
    request.EntityId = new Guid("1DCDEE97-35BB-44BE-8353-58BC36592656");

    // Execute the workflow.
    ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)service.Execute(request);


    With regards to passing parameter have a read of the thread below.
    http://social.microsoft.com/forums/en-US/crmdevelopment/thread/329ff385-fe28-4c2f-afb4-579b992417a6/

    Hassan.


    Hassan Hussain | http://hassanhussain.wordpress.com/ | http://www.mscrmvirtualusergroup.com/
    • Proposed as answer by Hassan Hussain Tuesday, December 29, 2009 9:56 AM
    • Marked as answer by Jim Glass Jr Wednesday, December 30, 2009 5:38 PM
    Tuesday, December 29, 2009 9:56 AM

All replies

  • Hi Chevie,

    You can run a workflow from code using the CRM SDK.

    The sample code below (taken from the CRM SDK) demonstrates how you would do this.



    [C#]
    // Set up the CRM Service.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
    token.AuthenticationType = 0;
    token.OrganizationName = "AdventureWorksCycle";

    CrmService service = new CrmService();
    service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
    service.CrmAuthenticationTokenValue = token;
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;

    // Create an ExecuteWorkflow request.
    ExecuteWorkflowRequest request = new ExecuteWorkflowRequest();

    //Assign the ID of the workflow you want to execute to the request.        
    request.WorkflowId = new Guid("b050f053-6968-dc11-bb3a-0003ffbad37a");

    //Assign the ID of the entity to execute the workflow on to the request.
    request.EntityId = new Guid("1DCDEE97-35BB-44BE-8353-58BC36592656");

    // Execute the workflow.
    ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)service.Execute(request);


    With regards to passing parameter have a read of the thread below.
    http://social.microsoft.com/forums/en-US/crmdevelopment/thread/329ff385-fe28-4c2f-afb4-579b992417a6/

    Hassan.


    Hassan Hussain | http://hassanhussain.wordpress.com/ | http://www.mscrmvirtualusergroup.com/
    • Proposed as answer by Hassan Hussain Tuesday, December 29, 2009 9:56 AM
    • Marked as answer by Jim Glass Jr Wednesday, December 30, 2009 5:38 PM
    Tuesday, December 29, 2009 9:56 AM
  • Hi,

    To run workflow from an custom page you could use ExecuteWorkflowRequest class.

    And for passing the parameter to custom iframe page.
    Check this article within msdn

    Regards,
    Nishant Rana



    http://nishantrana.wordpress.com
    Tuesday, December 29, 2009 10:00 AM