Reputation: 113
(Edited to better reflect the current state after help from the comments) I have a graph extension to which I have added a PXAction and PXButton etc. The method (now) accepts parameters. The button appears on the screen as expected an I can debug the action code in Visual Studio when the button is clicked.
// test params action.
public PXAction<InventoryItem> testParams;
[PXUIField(DisplayName = "Test Params", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXButton(CommitChanges = true)]
public virtual IEnumerable TestParams(PXAdapter adapter, [PXInt] int? siteID, [PXString] string testParamStr)
{
IEnumerable ret = adapter.Get();
if (adapter.Parameters != null)
{
int a = 0;
a++;
}
return adapter.Get();
}
After adding the parameters to my C# method and re publishing etc, the parameters appeared as options in the Parameter column below and I have been able to configure parameters to send through when I press the button on my stock item screen:
However... when I debug and look at the adapter, the method arguments (siteId and testParamsStr) are null as is adapter.Parameters and adapter.CommandArguments is an empty string.
As per Hugues Beauséjour's comment, the documentation for amending an existing action describes just this but how do we get at the values in the C# code? Looking at existing actions in Acumatica I don't think I'm missing any markup attributes etc.
Ideally I'd like a zero-code way to do what I'm trying to do but I'm not sure that's possible so I'm trying very short action code that passes values to a central class we will write to allow users to set up their own parameters that the central class will process so that they don't have to do any lengthy coding in the action code (the rest of the story is longer but that's the bit that's relevant to this question!).
Thanks!
Upvotes: 3
Views: 740
Reputation: 8278
This is how to pass parameters using code only. I'm posting it to help other people who might need it. For configuring the wizard parameters, this will not help much unfortunately.
// Graph Action
public PXAction<MyPrimaryDAC> MyAction;
[PXButton]
[PXUIField(DisplayName = "My Action")]
public virtual IEnumerable myAction(PXAdapter adapter)
{
// String value coming from JavaScript is read in adapter.CommandArguments
string payload = adapter.CommandArguments;
}
// JavaScript calls the graph action with a string parameter in payload variable
var ds = px_alls['ds'];
var actionName = 'MyAction';
var payload = 'string value passed to server';
ds.executeCallback(actionName, payload);
Upvotes: 1