Best advice and guidance RRS feed

  • Question

  • CRM2016

    I want to write a custom workflow that will process x number of selected records from a view

    I have tried creating a test custom workflow that just writes the recordid to a text file, but it appears that the  workflow is in a sense fired x number of times dependant on how many records are selected as apposed to the 'recordid's being passed to the a single instance of the workflow.

    It might help if i tried to explain what I'm trying to achieve. We get records in from clients that need to be processed at various times during the day. These records need to be written out to a single file with a fixed name

    i.e in my test scenario 3 record ids need to be written to a file called C:\text.txt

    however, on top of that when the workflow is first called, if the file exists it needs to be deleted.

    my code so far .. and i know its not pretty

           Public FILENAME As String = "C:\test.txt"
            Protected Overrides Sub Execute(executionContext As CodeActivityContext)
                    Dim context As IWorkflowContext = executionContext.GetExtension(Of IWorkflowContext)()
                    Dim serviceFactory As IOrganizationServiceFactory = executionContext.GetExtension(Of IOrganizationServiceFactory)()
                    Dim service As IOrganizationService = serviceFactory.CreateOrganizationService(context.UserId)
                    Using Processing As StreamWriter = New StreamWriter(FILENAME)
                    End Using
                Catch ex As Exception
                    Throw New InvalidPluginExecutionException(ex.Message.ToString)
                End Try
            End Sub

    any help or guidance would be very usefull

    Dont ask me .. i dont know

    Friday, April 7, 2017 3:16 PM

All replies

  • A CRM workflow instance will only ever run in the context of one record - i.e. if you select multiple records in a view, and run a workflow on them, there will be a separate workflow instance for each record. There is no way you can change this behaviour

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Friday, April 7, 2017 3:41 PM
  • Thank you, i think i understand. would you have any other suggestions as to how i might go about this this 

    Dont ask me .. i dont know

    Friday, April 7, 2017 4:26 PM
  • If I understood correctly, My approach would be, 

    1. Create an action that would take comma separate guids as input
    2. Create a ribbon button on grid and associated grid,
    3. on click of that button process the selected records into comma separated guids. Then, Call the action and pass the guids as input, use executeaction request or web api.
    4. Attach a plugin or custom workflow to the action, which in turn reads the comma separated guids and process them accordingly.

    Note: you can reuse this action anywhere.

    Ramanathan Rajendran MCTS - Dynamics CRM
    Sunday, April 9, 2017 3:55 AM