Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

How to read the Input Parameter(Entity Reference Type) of an Action into Plugin

Posted on by 379

Hi, 

I have a functionality to trigger the plugin on button click, so for that, I have created a custom button, on button click I am calling Js and there in Js I am triggering the action. This action I have created for the opportunity entity with Input parameter(type of entity reference).

All are going good my plugin also getting triggered but not able to ready the Input parameter value, like I don't know the syntax to ready the entity reference parameter of an action inside the plugin.

My Action

pastedimage1684948064007v1.png

My code

I am getting error here in yellow highlighted, line number 46.

Please suggest me the syntax to read this parameter value

  • Suggested answer
    Himanshu Kamboj Profile Picture
    Himanshu Kamboj 379 on at
    RE: How to read the Input Parameter(Entity Reference Type) of an Action into Plugin

    My plugin code is working fine, now I have created the XMLHTTP api for that action and now, I am passing the string parameter instead of entity reference.

  • Himanshu Kamboj Profile Picture
    Himanshu Kamboj 379 on at
    RE: How to read the Input Parameter(Entity Reference Type) of an Action into Plugin

    I have already attached the ss in above qtn.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: How to read the Input Parameter(Entity Reference Type) of an Action into Plugin

    Hi,

    Try to execute your custom action from c# console app to confirm it works.

    www.ashishvishwakarma.com/.../

    If it works then we know there is something wrong in js code 

    I would request you to generate js code using Dataverse rest builder tool

  • Suggested answer
    RE: How to read the Input Parameter(Entity Reference Type) of an Action into Plugin

    Hi Himanshu, 

    Can you post your code you are trying to ? 

    Thanks

  • Himanshu Kamboj Profile Picture
    Himanshu Kamboj 379 on at
    RE: How to read the Input Parameter(Entity Reference Type) of an Action into Plugin

    Object reference is not set to an instance of an object.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: How to read the Input Parameter(Entity Reference Type) of an Action into Plugin

    Hi,

    What is the error you are getting??

  • Himanshu Kamboj Profile Picture
    Himanshu Kamboj 379 on at
    RE: How to read the Input Parameter(Entity Reference Type) of an Action into Plugin

    Here I have attached my JS.

    function callActionToReopenOpp(primaryControl){

       var formContext = primaryControl;

       var Id = formContext.data.entity.getId().replace('{', '').replace('}', '');

       var target = {};

       target.entityType = "opportunity";

       target.id = Id;

       var req = {};

       req.entity = target;

       req.InputParam = target;

       req.getMetadata = function () {

               return {

                   boundParameter: "entity",

                   parameterTypes: {

                       "entity": {

                           typeName: "mscrm.opportunity",

                           structuralProperty: 5

                       }

                   },

                   "InputParam": {

                       "typeName": "mscrm.opportunity",

                       "structuralProperty": 5

                   },

                   operationType: 0,

                   operationName: "ReopenOpportunityFromDeclinedStage"

               };

       };

       Xrm.WebApi.online.execute(req).then(

           function success(result) {

               if (result.ok) {

                   //Success - No Return Data - Do Something

                   alert("Web API Action Called Successfully...");

               }

           },

           function(error) {

               Xrm.Utility.alertDialog(error.message);

           }

       );

    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans