web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

One workflow for multiple records

(0) ShareShare
ReportReport
Posted on by 1,703

CRM2016 onPremisis

I have a custom entity that das a multiline text field.

What I need to do is write a workflow / plugin that will literate through each selected record in a view and write that text field to a text file. 

The writing of the workflow to write or append the text file is easy enough providing only 1 record is selected.

I'm looking for advice suggestions on how to only have the workflow fire once and incorporate all the selected records

ie if I have 3 records selected , I would be looking for a single text file that contains

record1 Multiline text field data 

record2 Multiline text field data 

record3 Multiline text field data 

As far as I understand it, the workflows are fired on each selected record at the same time , which wouldn't work

Looking for suggestions to overcome this problem

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    tw0sh3ds Profile Picture
    5,600 on at

    Simply create a custom Action, which will take the ids of selected record as input parameter and will do the logic based on that input. You can register plugin on a custom Action and also Action can be really easily called from WebAPI. For example:

    community.dynamics.com/.../how-to-trigger-plugins-on-custom-messages-using-actions-in-dynamics-365

    Calling action:

    dynamicscrmcoe.com/calling-custom-action-using-javascript

    There are plenty of examples out there, I hope that you get the idea behind this.

  • Preeti Sharma Profile Picture
    2,678 on at

    Hi,

    You can run the workflow  on demand by selecting records and then run it whenever you need  it.

    Hope this helps :)

  • Pete_N Profile Picture
    1,703 on at

    Hi Pawel

    Thank you for your help so far. I have looked and read so much over the last few days, but still cannot quite get it. 

    I have been trying to follow this link which would best represent my end goal. Whilst I'm trying to get everything working, all I'm trying to do is click the button which would pass the Giud as a string to my plugin which created a text file.

    I'm basing everything on the two links you provided and this link https://www.wipfli.com/insights/blogs/connect-microsoft-dynamics-365-blog/160810-calling-custom-actions-from-javascript

    My Action

    Step.jpg

    My plugin Step

    Step.jpg

     My JavaScript

    function run(selectedItems)
    {
        var selectedItem = selectedItems[0];
        // Here you can use the information below to open a new window or whatever!
        alert("Id=" + selectedItem.Id + "\nName=" + selectedItem.Name + "\nTypeCode=" + selectedItem.TypeCode.toString() + "\nTypeName=" + selectedItem.TypeName);

    var inputParams = [
         { key: "IDStringList", type: Process.Type.String, value: selectedItem.Id.toString }];

    //Call the custom action
         Process.callAction("new_BuildSubmissionFile", inputParams, successCallback, errorCallback);
    }
    function successCallback(params) {
       //Get the result from the plugin and display the information in a notification
       var outputParamOne = params["OutputParamOne"];
       alert(outputParamOne )}
    function errorCallback(error, trace) {
       alert("Error: " + error, "ERROR", "myError");
    }

    When the button is clicked alert("Id=" + selectedItem.Id + "\nName=" + selectedItem.Name + "\nTypeCode=" + selectedItem.TypeCode.toString() + "\nTypeName=" + selectedItem.TypeName); is fired and displayed. I put this back in to check the button was firing the script. it seems that after that nothing happens. 

    my Plugin ( simple to get the hang of this process

    Imports System.Globalization
    Imports System.IO
    Imports System.Net
    Imports System.Text
    Imports System.Xml
    Imports Microsoft.Xrm.Sdk

    Namespace BuildBacsFile
        Public Class clsBuildBACSFile
            Implements IPlugin

            Public Sub Execute(serviceProvider As IServiceProvider) Implements IPlugin.Execute
                Using Reportprocessing As StreamWriter = New StreamWriter("\\CBI018\Logs\BACS_Sub_Builder.txt")
                    Reportprocessing.WriteLine("Started")
                End Using


                Dim tracingService As ITracingService = DirectCast(serviceProvider.GetService(GetType(ITracingService)),
                                            ITracingService)

                Dim localContext As IPluginExecutionContext =
                        DirectCast(serviceProvider.GetService(GetType(IPluginExecutionContext)), IPluginExecutionContext)
                Dim output As String = String.Empty
                Try
                    If localContext Is Nothing Then
                        Throw New InvalidPluginExecutionException("localContext")
                    End If
                    Dim TransactionsetRef As EntityReference = CType(localContext.InputParameters("Target"), EntityReference)
                    Dim StringIDs As String = CStr(localContext.InputParameters("IDStringList"))
                    Using Reportprocessing As StreamWriter = New StreamWriter("\\CBI018\Logs\BACS_Sub_Builder.txt")
                        Reportprocessing.WriteLine("Started")
                    End Using
                    output = "Completed"
                Catch exception As WebException
                    Dim str As String = String.Empty
                    If exception.Response IsNot Nothing Then
                        Using reader As StreamReader = New StreamReader(exception.Response.GetResponseStream())
                            str = reader.ReadToEnd()
                        End Using

                        exception.Response.Close()
                    End If

                    If exception.Status = WebExceptionStatus.Timeout Then
                        Throw New InvalidPluginExecutionException("The timeout elapsed while attempting to issue the request.", exception)
                    End If

                    Throw New InvalidPluginExecutionException(String.Format(CultureInfo.InvariantCulture, "A Web exception occurred while attempting to issue the request. {0}: {1}", exception.Message, str), exception)
                End Try
                localContext.OutputParameters("OutputParamOne") = output

            End Sub

        End Class
    End Namespace

    It appears that the plugin is not fired at all. I'm presuming it something to do with the process.js library . I got this from processjs.codeplex.com

    Being completely new to script .. I'm at a total loss as to why this isn't working or how to fix it.

  • Jeet Gandhi Profile Picture
    320 on at

    Hi,

    As per my suggestion, custom workflow / plugin could be the simplest way to implement the requirement. In the code, all you need to do is to fetch the custom entity records based on the conditions specified in the view.

    Then iterate through each fetched record and append the value of the multi line text field in the text file object.

    .Net framework contains various classes that helps to create a text file.

    Please let me know if you require more help regarding coding.

    Thanks,

    Please mark the answer if found helpful:)

  • Pete_N Profile Picture
    1,703 on at

    Hi,

    Thank you for your reply, I think I am in need of a lot of help on this one, step learning curve for me.

    The end result I'm looking to get to is that when a user click the custom button, the guid if each selected record is passed as a single string separated by a ; (ie guid 1;guid2 ett) to the plugin, and to get a return from the plugin if completed or the error if there are any  

  • Jeet Gandhi Profile Picture
    320 on at

    Hi,

    As per the end result you are expecting, it seems like you require a ribbon button on the landing page of the custom entity. On click of the button, you require to download a text file that should contain field values of the selected custom entity records.

    If my understanding is correct, than I think the implementation would not be much complex. It is possible to implement the functionality just using JavaScript code executed on click of the button.

    If you require further help related to JavaScript coding, please reply me so that I can assist you for the same.

    Thank you,

    Please mark the answer if found helpful :))

  • Pete_N Profile Picture
    1,703 on at

    Hi Jeet

    I have managed to progress a little further 

    function run(selectedItems)
    {
     try {
        var selectedItem = selectedItems[0];
        // Here you can use the information below to open a new window or whatever!
        alert("Id=" + selectedItem.Id + "\nName=" + selectedItem.Name + "\nTypeCode=" + selectedItem.TypeCode.toString() + "\nTypeName=" + selectedItem.TypeName);
    var inputParams = [
         {  key: "IDStringList", type: Process.Type.String, value: selectedItem.Id.toString  },
          { key: "Target", type: Process.Type.EntityReference, value:  new Process.EntityReference("new_transactionsets", Xrm.Page.data.entity.getId())
     } ];
    //Call the custom action
         Process.callAction("new_buildsubmissionfile", inputParams, successCallback, errorCallback);
    }
     catch(err)
    {
     alert(err)
    }
    }

    I'm suspecting the problem is the Target as all I have seen in threads relates to the form and not a view

    the error I'm getting is 

    0081.error.jpg

  • Jeet Gandhi Profile Picture
    320 on at

    Hi,

    Thanks for your reply. I suggest you to validate my understanding first so that I can help you further with finalizing the approach and help you with the coding part.

    As per my understanding,  it seems like you require a ribbon button on the landing page of the custom entity. On click of the button, you require to download a text file that should contain field values of the selected custom entity records.

    Please validate above understanding to help you out further.

    Thanking you,

  • Pete_N Profile Picture
    1,703 on at

    Hi Jeet,

    very close. I don't want to download a file, what I need is the selected record id's ( record guid's) to a string variable that I can then pass to a custom action and plugin

    from what I have read I cannot pass a list or id's, so would need to pass the ids, as a string

    i.e

    if 3 records are selected I need to end up with a string of guid1;guid2;guid3 , I can then pass this string through to my custom workflow and plugin

  • Suggested answer
    tw0sh3ds Profile Picture
    5,600 on at

    This: Xrm.Page.data.entity.getId() is failing, because this works only on an entity form and you are on entity grid as far as I understand, so Xrm.Page.data is undefined. You should use selectedItem.Id (I'm not sure, but maybe you will have to trim "{" and  "}" from this Id)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans