Announcements
Hey,
Could someone help me, I'm trying to pass a parameter from javascript to a plugin, but I'm not having success.
Here are codes:
var req = {};
req.getMetadata = function () {
return {
boundParameter: null,
parameterTypes: {"CNPJ": CNPJ_data_texto},
operationType: 0,
operationName: "new_TestedeProcesso"
};
};
var CNPJ = (string)context.InputParameters["CNPJ"];
((IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext))).InputParameters["CNPJ"] = CNPJ;
Hi, seems like you are not passing any value when calling your action... try this.
var req = {}; req.CNPJ = CNPJ_data_texto; req.getMetadata = function () { return { boundParameter: null, parameterTypes: { "CNPJ": { typeName: "Edm.String",//I suppose it's string structuralProperty: 1 } }, operationType: 0, operationName: "new_TestedeProcesso" }; };
now for store the value just use this line in C#
var CNPJ = (string)context.InputParameters["CNPJ";
in the backend you are right
regards.
Hello Felipe,
That's exactly why you should use Action or Custom API.
The Custom APIs where created by Microsoft for that purpose, please read the official documentation. It's a component that makes use of a Plugin class to run the logic, so your C# code can be reused there.
Please check this example about how to create Custom API: https://markcarrington.dev/2020/10/22/cds-custom-apis/
Hope this helps you.
Please mark the answer as verified if helpful. That will help others in future.
Hey,
Thanks for the answer.
I'm building an integration, I made the whole structure using C #, that's why I use the plugin.
As I am creating a custom screen within the dynamics, I would like the javascript to call the plugin based on the data that users put on that screen, but the variable arrives blank and I cannot perform the query correctly.
Hello,
Why trying to pass the parameters from JavaScript to Plugin? I would not recommend that approach.
If the request is coming from Client-Side or as External Web Request, please evaluate the option of calling an Action or Custom API.
Hope this helps you.
Please mark the answer as verified if helpful. That will help others in future.
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156