Good Day Mam/Sir,
I have a button. I need to get the name of my button then pass it to static void main in class.
Please see below my codes:
Thanks in advance :)
---------------------------------------------------------Start code of Button: Clicked-------------------------------------------------------------------------------------------
void clicked()
{
PurchFormLetter purchFormLetter;
purchFormLetter.parmBtnID(this.name());
super();
}
---------------------------------------------------------End code of Button: Clicked-------------------------------------------------------------------------------------------
---------------------------------------------------------Start code of parmBtnID-------------------------------------------------------------------------------------------
String30 parmBtnID(String30 _btnID = btnID)
{
btnID = _btnID;
return btnID;
}
---------------------------------------------------------End code of parmBtnID-------------------------------------------------------------------------------------------
---------------------------------------------------------Start code of static client void main-------------------------------------------------------------------------------------------
static client void main(Args args)
{
Common record;
int parmEnum;
Object callerForm;
IdentifierName callerFormName;
MenuItemNameAction callerMenuItem;
boolean isProforma;
FormDataSource recordDataSource;
container dataSourceRecordsPacked;
container cachedArgs;
PurchTable purchTable;
boolean recordExists;
Counter numberOfRecords;
str className, methodName;
SysOperationExecutionMode mode;
container packedPurchFormletter;
FormletterOutputContract outputContract;
PurchFormLetter purchFormLetter;
VendPurchOrderJour vendPurchOrderJourOld,vendPurchOrderJourNew;
String30 myID;
if (!args)
{
throw error("@SYS25407");
}
[className, methodName, mode] = FormLetterServiceController::parseServiceInfo(args);
record = args.record();
parmEnum = args.parmEnum();
callerForm = args.caller();
callerMenuItem = args.menuItemName();
if (callerForm)
{
callerFormName = args.caller().name();
}
else if(args.menuItemName() == identifierStr(EPVendInvoice) || args.menuItemName() == identifierStr(EPVendInvoiceVendAdvance))
{
callerFormName = args.name();
}
isProforma = FormLetterServiceController::isMenuItemProforma(args.menuItemName());
if (record && record.dataSource())
{
recordDataSource = record.dataSource();
dataSourceRecordsPacked = FormLetter::getFormRecord(recordDataSource);
}
cachedArgs = [#CachedArgsList];
packedPurchFormletter = PurchFormLetter::mainOnServer(cachedArgs, record, callerForm, dataSourceRecordsPacked);
if (packedPurchFormletter != conNull())
{
purchFormLetter = PurchFormLetter::construct(parmEnum, className, methodName, mode, callerMenuItem);
purchFormLetter.unpack(packedPurchFormletter);
purchFormLetter.init();
purchFormLetter.prePromptModifyData();
if (!purchFormLetter.shouldSkipPrompt() && purchFormLetter.prompt())
{
purchFormLetter.run();
outputContract = purchFormLetter.getOutputContract();
numberOfRecords = outputContract.parmNumberOfOrdersPosted();
}
}
if (numberOfRecords
// <GEERU>
|| (purchFormLetter && purchFormLetter.doRefreshCallerDataSource())
// </GEERU>
)
{
if (callerForm && formHasMethod(callerForm,identifierStr(interCompanyRefreshCache)))
{
callerForm.interCompanyRefreshCache();
}
if (recordDataSource)
{
if (record is PurchTable)
{
purchTable = record as PurchTable;
recordExists = PurchTable::exist(purchTable.PurchId);
}
else
if (record is PurchParmTable)
{
recordExists = false;
}
// <GEERU>
else
if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoRU]) &&
record is VendPackingSlipJour)
{
recordExists = VendPackingSlipJour::findRecId(record.RecId).RecId;
}
else if (record is EGAISWaybillJour_RU)
{
recordExists = EGAISWaybillJour_RU::findRecId(record.RecId).RecId;
}
// </GEERU>
// <GEEPL>
else if (record is PlSADTable)
{
recordExists = PlSADTable::findRecId(record.RecId).RecId;
}
// </GEEPL>
FormLetter::reFreshCallerDataSource(recordDataSource,
recordExists,
(numberOfRecords > 1));
myID=purchFormLetter.parmBtnID();
info(strfmt("my BTN name is: ",myID));
/*
//-------------------------------------Start of Old VendPurchOrderJour------------------------------------------------------------
select firstOnly vendPurchOrderJourOld order by vendPurchOrderJourOld.RecId asc
where vendPurchOrderJourOld.PurchId == purchTable.PurchId ;
//-------------------------------------End of Old VendPurchOrderJour------------------------------------------------------------
if(vendPurchOrderJourOld.PurchId)
{
ttsBegin;
select forupdate vendPurchOrderJourNew order by vendPurchOrderJourNew.RecId desc
where vendPurchOrderJourNew.PurchId == purchTable.PurchId ;
vendPurchOrderJourNew.PurchaseOrderIdOld = vendPurchOrderJourNew.PurchaseOrderId;
vendPurchOrderJourNew.PurchaseOrderId=vendPurchOrderJourOld.PurchaseOrderId;
vendPurchOrderJourNew.update();
ttsCommit;
}
*/
}
}
}
---------------------------------------------------------End code of static client void main-------------------------------------------------------------------------------------------
*This post is locked for comments
Great!
Thank you so much, Mr Pedro. :)
Hi Gelo,
Now I understand your problem. You need to change some behavior on the PurchFormLetter class, but you cannot use the menu item properties because they were already used by the framework.
So I will keep things simple for you.
Probably Microsoft engineers had the same problem when they were developing D365 renewed FormLetter framework, because the caller menu item name is a global variable on every FormLetter class and it's extracted from the args parameter on the main() method.
If you open up the PurchFomLetter code and search for "callerMenuItem" you will find several references to it. So I think you should use the same trick and base your conditions on the caller menu item (not the button).
Here is a sample code:
if(purchFormLetter.parmCallerMenuItem() == menuItemActionStr(PurchFormLetter_PurchaseOrder_Action)) { // Standard process } else { // Customized process }
You can do something like this. Create a class say Class1 and have 2 methods method1 and method2. These can be static methods. Now, on clicked method of first button can call method1 and second button can call method2. method1 can perform confirmation and generate new PO confirmation. method2 can copy existing PO confirmation. Does it make sense?
button1 > clicked method
Class1::method1()
button2 > clicked method
Class2::method2()
If button1 and button2 are menu items and there is same class behind both. Then based on menu item name, different actions can be performed within class.
Thank you for your response Khushhal,
Can you please give me examples or link that related that you have mentioned?
Thank you
Thank you, Pedro
how I can do that if the enum has existed value?
Please see the attached image below:
Thanks sir,
There are already 2 separate button. Just call separate methods for their own logic to trigger from clicked method of these buttons. Passing button name doesn't sound very good design.
Hello Gelo,
It's a bad design to rely on form control names for your logic, if you have two buttons that will perform similar logic you should create two separate menu items and use the Enum property of each new menu item to identify which process must be executed by the class.
If it's a complex process, you should consider having a base class and two child classes. Then on the main() method of your base class you can use the enum value from the _args parameter to construct the right child object.
sorry, sir Martin for the wrong typo.
I mean "It will not generate a new Purchase Order Confirmation". not "Generate a new Purchase Order"
I can't say I understand your logic. When you say "it will not generate a new Purchase Order", I guess you mean a new confirmation, because this process shouldn't create a new order. And if you don't create a confirmation, is it true that you confirmed the order? I wouldn't say so. Also, creating a copy of an old confirmation doesn't make sense to me. It's for a previous state of the order, which may be very different from the current one.
Anyway, if you insist of copying an old confirmation, create a class for this logic, then a menu item pointing to this class and drage the menu item to the form, which will create a new menu item button calling your class.
Don't mix it with actual confirmation posting and don't base your business logic on form control names.
Thank you for your replied sir martin.
I have 2 buttons in my form (PurchTableListPage). The first button is to Confirm the PO then it will generate a new Purchase order confirmations.
and the 2nd button is to confirm the PO but it will not generate a new Purchase Order, it will just copy the existing purchase order confirmations.
my logic is to get the name of the button that clicked by the user, it will pass the values to static void main of the class (PurchFormLetter)
. Once the static void main detected that the 2nd button triggered, it will perform the code of the below:
myID=purchFormLetter.parmBtnID();
if(myID=="2ndButtonName")
{
select firstOnly vendPurchOrderJourOld order by vendPurchOrderJourOld.RecId asc
where vendPurchOrderJourOld.PurchId == purchTable.PurchId ;
if(vendPurchOrderJourOld.PurchId)
{
ttsBegin;
select forupdate vendPurchOrderJourNew order by vendPurchOrderJourNew.RecId desc
where vendPurchOrderJourNew.PurchId == purchTable.PurchId ;
vendPurchOrderJourNew.PurchaseOrderIdOld = vendPurchOrderJourNew.PurchaseOrderId;
vendPurchOrderJourNew.PurchaseOrderId=vendPurchOrderJourOld.PurchaseOrderId;
vendPurchOrderJourNew.update();
ttsCommit;
}
}
Thanks,,
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,802 Super User 2024 Season 2
Martin Dráb 229,129 Most Valuable Professional
nmaenpaa 101,154