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)

Action not firing plugin

(0) ShareShare
ReportReport
Posted on by 1,703

CRM2016 On Premises

With a lot of help, I have added a button to a view, added the javascript and created an action to fire a plugin .. but Its not working and I just cannot see why

view is on New_transactionsets

JavaScript

    function BuildBACSFile(selectedItems)
{
 try {
       alert("Test 1");
       var stringlist ="";
       for (var i = 0; i < selectedItems.length; i++)
      {
        if(stringlist != "")
        {
            if(selectedItems[i] != null && selectedItems[i] != undefined)
                stringlist = stringlist +  "," +  selectedItems[i].Id;

        }
        else
        {  
            if(selectedItems[i] != null && selectedItems[i] != undefined)
                stringlist = selectedItems[i].Id;
        }           

      } 

       alert(Test 2);
       var inputParams = [
      { key: "ParameterGuids", type: Process.Type.String, value: stringlist }];

//Call the custom action
     Process.callAction("new_BuildMultiBACSFile", inputParams, successCallback, errorCallback);
 }
 catch(err)
{
 alert(err)
}
}

function successCallback(params) {
    alert("successCallback");
   //Get the result from the plugin and display the information in a notification
   var outputParamOne = params["PluginResponse"];
   alert(outputParamOne )}
function errorCallback(error, trace) {
      alert("errorCallback");
   alert("Error: " + error, "ERROR", "myError");
}


The Action

4505.Action.jpg

I have registered the plugin successfully

Plugin in code ( simple for testing .. just writing to a text file )

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

Namespace BuildBacsFile
    Public Class clsBuildBACSFile
        Implements IPlugin

        Public Sub Execute(serviceProvider As IServiceProvider) Implements IPlugin.Execute
            writetolog("Started ")

            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 parmsqlLedgerKey As String = CStr(localContext.InputParameters("ParameterGuids"))

                writetolog("Started " & parmsqlLedgerKey)
                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("PluginResponse") = output

        End Sub
        Public Function writetolog(message As String) As Boolean
            Using Errorprocessing As StreamWriter = File.AppendText("C:\Logs\workflow.txt")
                Errorprocessing.WriteLine(message)
            End Using
            Return True
        End Function
    End Class
End Namespace


When I have selected a record and clicked the button, I get the alert Test 1 and Test 2. ( I have shown that the stringlist contains data ) . Nothing else, no err alert and no workflow.txt file. It is as though the action is not firing the plugin. on the Process, I have looked and there are no process session listed. Im at a loss as to where to look to try and resolve this

*This post is locked for comments

I have the same question (0)
  • rthompson Profile Picture
    1,532 on at

    Hi PeteN,

    I don't see where you are calling your EndPoint - 

    organizationUrl 

    Here's code that I am working with that someone helped me with.

      function CallActionPlugin(datatracking) {
    
          var isStatus;
          var organizationUrl = serverUrl;
    
          var query = "new_CreateNewCaseDataSheet"
    
          var data  = JSON.stringify(datatracking);
    
          $.ajax({
              url: organizationUrl + "/api/data/v8.0/new_CreateNewCaseDataSheet",
              type: 'POST',
              contentType: "application/json; charset=utf-8",
              datatype: "json",
              data: data,
              success: function (responseText) {
                  //var jsonData = JSON.stringify(responseText); 
                  //var getStatus = JSON.parse(this.responseText);
                  //isStatus = getStatus.isStatus;
    
                  alert(" -- Action Called - 23");
                  //    updateMap(myArr); 
                  window.close();
                  return false;
                  
              },
              error: function (jqXHR, exception) {
                 var msg = '';
                 if (jqXHR.status === 0) {
                    msg = 'Not connect.\n Verify Network.';
                 } else if (jqXHR.status == 404) {
                    msg = 'Requested page not found. [404]';
                 } else if (jqXHR.status == 500) {
                    msg = 'Internal Server Error [500].';
                 } else if (exception === 'parsererror') {
                    msg = 'Requested JSON parse failed.';
                 } else if (exception === 'timeout') {
                    msg = 'Time out error.';
                 } else if (exception === 'abort') {
                    msg = 'Ajax request aborted.';
                 } else {
                    msg = 'Uncaught Error.\n' + jqXHR.responseText;
                 }
                 alert(msg);
              }
          });


  • C. Jensen Profile Picture
    384 on at

    Hi

    In the picture of your action, it says "No steps have been added". Unless you have modified the action later, you will have to call you plugin in a step, and pass the parameters to the plugin.

    /Christian

  • Verified answer
    Mark Carrington Profile Picture
    334 on at

    Without the definition of Process.callAction it's hard to see whether or not the request to invoke the action would be properly formed or not. You might be able to see some more information if you use Fiddler to check you're making the expected request to CRM to invoke the action and see what information, if any, you're getting back. This might help to isolate the problem to client- or server-side.

  • Verified answer
    Mark Carrington Profile Picture
    334 on at

    The plugin would be registered to the pre/post operation steps of the action directly using Plugin Registration Tool, rather than explicitly invoking it in the body of the action. If the plugin is going to set the value of the output parameters though, it should be registered in the post operation step.

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