Actions, input parameters and “Object reference not set to an instance of an object” exception

While playing with Actions, I wrote a simple .Net code that invoked the execution of an Action:

During testing, I got a really weird and unclear error – “Object reference not set to an instance of an object.”:

After some investigation, I realized that if you have declared the input parameters of Entity, EntityReference, EntityCollection, Money, Picklist or string type (even not marked as required!) to make the code work without exception, you need to pass this parameters:


  1. Hi Andrew,

    I am trying to retrieve the filtered contacts in my result. But I too get the same error as you have shown above. I have one inputparameters of type String. This is how I am trying to achieve and this piece of code was working before but not sure why its not working now.
    Guid caseId;
    if (Guid.TryParse(Request[“refid”], out caseId))
    string inputRequest = “{\”InputParameters\”:[{\”RequestType\”:\”FilterContacts\”, \”InputValues\”: [ { \”Key\”:IncidentId, \”Value\”:” + “\”” + caseId + “\”” + ” }]}]}”;
    OrganizationRequest request = new OrganizationRequest(“ava_MessageBus”);
    request.Parameters.Add(new KeyValuePair(“InputParameters”, inputRequest));
    object response = ServiceContext.Execute(request);//I got an error here – Object reference not set to an instance of an object

    // Call Java Script method from client side
    string script = “javascript:FilterContacts(‘” + caseId + “‘)”;
    Page.ClientScript.RegisterStartupScript(this.GetType(), “Filter”, script, true);
    throw new Exception(“CaseId is missing”);

    Please suggest here.

    1. There are several possible answers – doublecheck that code of your plugin works fine (an error occurs because reference of collection’s missing element).
      Also check that code runs in Post-Operaation.
      Can you also provide a screenshot of your action please?

  2. Plugin code works fine. The code which I provided above was being used in AdxPortal for the same functionality what I was trying in Dynamics 365 by using the below JS. I wanted to use the JSON response but not sure how to convert and bind my lookup. Hence I commented that part and used string. But I get null in the request (Object reference not set to an instance of an object)
    function () {
    var caseId = Xrm.Page.getAttribute(“ava_case”).getValue();

    if ((caseId !== null) && (caseId[0].id !== null)) {
    var caseGUID = Avanade.CT.Common.CleanupGuid(caseId[0].id);

    var data = {};
    data.InputParameters = “{\”InputParameters\”:[{\”RequestType\”:\”FilterContacts\”, \”InputValues\”: [ { \”Key\”:IncidentId, \”Value\”:” + “\”” + caseGUID + “\”” + ” }]}]}”;

    //var data = {
    // InputParameters: [
    // {
    // RequestType: “FilterContacts”,
    // InputValues: [
    // {
    // Key: “IncidentId”,
    // Value: caseId
    // }
    // ]
    // }
    // ]

    // Execute Custom Action “ava_MessageBus”
    //Avanade.CT.Common.Action.ExecuteUnboundAction(“ava_MessageBus”, window.JSON.stringify(data), Avanade.CT.CaseContact.FilterContactsSucessCallBack);
    Avanade.CT.Common.Action.ExecuteUnboundAction(“ava_MessageBus”, data, Avanade.CT.CaseContact.FilterContactsSucessCallBack);

    Not sure how you added the screenshot here.
    This what I have in my custom action – ava_messagebus
    Entity – None(global)
    Inputparameters – string – optional – Input
    Results – string – optional – Output

    1. Property names have to be the same. In your code you use InputParameters and in action description you use Inputparameters.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.