3

(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:

Action Properties

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!

Chris Rothery
  • 113
  • 1
  • 7
  • 1
    Hi Chris, there are multiple examples of Actions with parameters in PXGraph "SOOrderEntry". eg: public virtual IEnumerable CreateShipmentReceipt(PXAdapter adapter, [PXDate] DateTime? shipDate, [PXInt] int? siteID) => CreateShipment(adapter, shipDate, siteID, SOOperation.Receipt); – diegoapereza Jan 28 '22 at 02:23
  • Thank you that's a great pointer and after adding a PXInt and PXString parameter, building, publishing etc, my parameter names are now options in the Parameter column of the Action Parameters tab. However, stopping the debugger in the action code after the button has been pressed results in null for those parameters (and adapter.Parameters is null and adapter.CommandArguments is an empty string). I feel so close and the image of a whole solution based on this is forming in my mind once this is unlocked and users can pass parameters to my action code in this manner! – Chris Rothery Jan 31 '22 at 17:54
  • Yes should be possible. I've done it in the past. In documentation, go to section 'To Customize an Existing Action' : https://help-2020r2.acumatica.com/Help?ScreenId=ShowWiki&pageid=cbbac950-4172-42c7-b950-a589a87df249 – Hugues Beauséjour Feb 01 '22 at 19:35
  • @Hugues, I agree it should be possible :) that documentation says "For a graph action you are customizing, specify the action parameters." which confirms that what the UI is offering is resonable (you should be able to supply action parameters). They remain null in my action code though :( will edit the question/sample code to match closer to current stage of testing. – Chris Rothery Feb 02 '22 at 14:52
  • I posted a 'only code' approach answer as I don't have time to troubleshoot the 'no code' approach. Maybe it will help a bit but I think 'no code' approach is different. – Hugues Beauséjour Feb 02 '22 at 18:39

1 Answers1

1

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);
Hugues Beauséjour
  • 8,067
  • 1
  • 9
  • 22