Skip to content

Instantly share code, notes, and snippets.

@YuriyZaletskyy
Created May 4, 2021 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YuriyZaletskyy/698abc111595a54f670d0cd85a832d49 to your computer and use it in GitHub Desktop.
Save YuriyZaletskyy/698abc111595a54f670d0cd85a832d49 to your computer and use it in GitHub Desktop.
Dynamic Selector Functionality
namespace MyProject
{
public class APInvoiceEntryExt : PXGraphExtension<APInvoiceEntry>
{
public PXSelect<MyCommand> Commands;
public PXSelect<GLTran> GLTrans;
public PXSelect<FixedAsset> FixedAssets;
protected void MyCommand_CommandData_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
var row = (MyCommand)e.Row;
if (row == null)
return;
PXFieldState state = PXFieldState.CreateInstance(e.ReturnState,
typeof(string), false, true, 1, null, null, null, typeof(MyCommand.commandData).Name);
e.ReturnState = state;
var id = (int)row.CommandID;
if (id == 0)
{
state.ViewName = nameof(FixedAssets);
state.DescriptionName = nameof(FixedAsset.description);
state.FieldList = new string[]
{
nameof(FixedAsset.assetID),
nameof(FixedAsset.description),
nameof(FixedAsset.assetTypeID),
nameof(FixedAsset.assetCD)
};
var selectorCache = Base.Caches<FixedAsset>();
state.HeaderList = new string[]
{
PXUIFieldAttribute.GetDisplayName<FixedAsset.assetID>(selectorCache),
PXUIFieldAttribute.GetDisplayName<FixedAsset.description>(selectorCache),
PXUIFieldAttribute.GetDisplayName<FixedAsset.assetTypeID>(selectorCache),
PXUIFieldAttribute.GetDisplayName<FixedAsset.assetCD>(selectorCache),
};
}
else
{
state.ViewName = nameof(GLTrans);
state.DescriptionName = nameof(GLTran.tranDesc);
state.FieldList = new string[]
{
nameof(GLTran.module), nameof(GLTran.lineNbr), nameof(GLTran.batchNbr),
nameof(GLTran.accountID), nameof(GLTran.tranDesc), nameof(GLTran.branchID)
};
var selectorCache = Base.Caches<GLTran>();
state.HeaderList = new string[]
{
PXUIFieldAttribute.GetDisplayName<GLTran.module>(selectorCache),
PXUIFieldAttribute.GetDisplayName<GLTran.lineNbr>(selectorCache),
PXUIFieldAttribute.GetDisplayName<GLTran.batchNbr>(selectorCache),
PXUIFieldAttribute.GetDisplayName<GLTran.accountID>(selectorCache),
PXUIFieldAttribute.GetDisplayName<GLTran.tranDesc>(selectorCache)
};
}
state.DisplayName = PXUIFieldAttribute.GetDisplayName<MyCommand.commandData>(cache);
state.Visible = true;
state.Visibility = PXUIVisibility.Visible;
state.Enabled = true;
}
public PXAction<PX.Objects.AP.APInvoice> CommandButton;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Command Button")]
protected void commandButton()
{
Commands.AskExt();
}
}
}
@giri777
Copy link

giri777 commented Feb 10, 2022

Hi @YuriyZaletskyy
Can you send the CommandData field code in MyCommand DAC.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment