locked
how can i run a workflow on an Opportunity only if it hasn't run before? RRS feed

  • Question

  • Hi all,

    I want to run a worflow on an Opportunity, but ONLY if it has NOT run before...

    We had a slight issue where the workflow had stopped running, but now we have fixed this, we need to run the workflow for those Opportunities that it didn't run for. The workflow simply creates tasks for an opportunity in a given state, but i cant find anyway of doing an adv find to find all opportunities in 'State A' where these tasks DONT exist.

    Any help is much appreciated...

    Thank you! :-)
    Wednesday, March 17, 2010 11:16 AM

Answers

  • Hi Basha

    Unfortunately its advanced finds limitation. It can query only existing data
    refer http://dmcrm.blogspot.com/2008/02/creating-saved-views-that-advanced-find.html

    Note: Hope we can perform it in unsupported method at our own risk.

    You have to do this manually of through code. (SUPPORTED method)

    You can use RetrieveMultiple or FetchXML to obtain the needed opportunity records (which dont have notes associated to it.)
    refer
    http://technet.microsoft.com/en-us/library/aa680905.aspx
    http://msdn.microsoft.com/en-us/library/bb928434.aspx

    You can run the workflow using ExecuteWorkflow method.

        // Create an ExecuteWorkflow request.
        ExecuteWorkflowRequest requestwkf = new ExecuteWorkflowRequest();
        //Assign the ID of the workflow you want to execute to the request.        
        requestwkf.WorkflowId = new Guid("AB5F7C40-58FF-4A13-9B19-5BB7180D914E");
        //Assign the ID of the entity to execute the workflow on to the request.
        // request.EntityId =new Guid("7D882015-562B-DF11-A3ED-005056993911");
        requestwkf.EntityId = new Guid(con.opportunity.Value.ToString());
        // Execute the workflow.
        ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)service.Execute(requestwkf);


    Regards
    Vinoth

    Wednesday, March 17, 2010 12:12 PM

All replies

  • Change your workflow to run on-demand.

    Use advanced find to locate all opportunites in 'State A' where these tasks DONT exist.

    Select your workflow from tools bar of ADV find and run on all opportunities retun by ADV find.


    http://www.allaboutdynamics.com
    Wednesday, March 17, 2010 11:40 AM
  • hi,

    thats the problem - i cant use adv find to find opportunities where a task does not exist. Unless you can tell me how?
    I have tried Opportunities > Regarding Activity > Subject Does Not Contain 'string'> Find but this does not return the correct results as it will still find opportunities that have multiple tasks one of which may have the string i am looking for and another which doesn't. because there is a task that doesn't have the string i am looking for it will still display this opportunity!
    Wednesday, March 17, 2010 11:44 AM
  • Hi Basha

    Unfortunately its advanced finds limitation. It can query only existing data
    refer http://dmcrm.blogspot.com/2008/02/creating-saved-views-that-advanced-find.html

    Note: Hope we can perform it in unsupported method at our own risk.

    You have to do this manually of through code. (SUPPORTED method)

    You can use RetrieveMultiple or FetchXML to obtain the needed opportunity records (which dont have notes associated to it.)
    refer
    http://technet.microsoft.com/en-us/library/aa680905.aspx
    http://msdn.microsoft.com/en-us/library/bb928434.aspx

    You can run the workflow using ExecuteWorkflow method.

        // Create an ExecuteWorkflow request.
        ExecuteWorkflowRequest requestwkf = new ExecuteWorkflowRequest();
        //Assign the ID of the workflow you want to execute to the request.        
        requestwkf.WorkflowId = new Guid("AB5F7C40-58FF-4A13-9B19-5BB7180D914E");
        //Assign the ID of the entity to execute the workflow on to the request.
        // request.EntityId =new Guid("7D882015-562B-DF11-A3ED-005056993911");
        requestwkf.EntityId = new Guid(con.opportunity.Value.ToString());
        // Execute the workflow.
        ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)service.Execute(requestwkf);


    Regards
    Vinoth

    Wednesday, March 17, 2010 12:12 PM
  • you are all making this way to complicated.

    Add a bit field
    have the WF update the Bit field
    Have the WF check if the bit field is maked yes, if it is cancel WF

    This requires no code other that hiding that bit field.

    If you want to run a WF numerous times, make it an integer and increase teh value by one
    Withers
    Wednesday, March 17, 2010 9:16 PM
  • Add a field 'WF Ran' to opportunity. In your workflow have it set the field to True. Run Advanced Find where field is False or Does not contain Data.  

    Tuesday, August 3, 2010 4:30 AM