Hi,
while creating a free text invoice, when I choose a customer account, it will update the default Dimension (Business unit) in the free text invoice Header. I have created a custom field HSHTSiteId in CustInvoiceTable which has InventSiteID as EDT.
My requirement is when I modify HSHTSiteId & choose some other value then default Dimension in free text invoice Header must be updated to the default dimension related to HSHTSiteId as InventSiteID has default Dimension related to it.
I have write onModified Event Handler on CustInvoiceTable:
public static void CustInvoiceTable_HSHTSiteId_OnModified(FormControl sender, FormControlEventArgs e) { CustInvoiceTable custInvoiceTable; FormRun element = sender.FormRun(); FormStringControl siteID = element.design().controlName(formControlStr(CustFreeInvoice,CustInvoiceTable_HSHTSiteId)); select custInvoiceTable; if (siteID) { custInvoiceTable.DefaultDimension = LedgerDimensionDefaultFacade::serviceMergeDefaultDimensions(custInvoiceTable.DefaultDimension, InventSite::find (custInvoiceTable.HSHTSiteId).DefaultDimension); } }
But the Default Dimension value is not updating in Freetextinvoice Header. I debug the code & found getting 0 value returned.
Can anyone suggest How can I do this.
Thanks
Rahul
Hi Mohit,
Thanks for the reply.
I used this.HSHTSiteId to pass into find method, now I am able to fetch updated value without even saving. It gets worked perfectly.
Thanks,
Rahul
Hi Rahul, Have you tried the code I suggested above? You are using modifiedField method and checking HSHTSiteId field, so when user add/modify value in HSHTSiteId field, you can get it without even saving record first. Please comment Line#14 and replace it with below code and see if you get the value without saving record.
inventSiteId = this.HSHTSiteId;
Hi Mohit,
Below Code is working fine but firstly I need to save the record after selecting a siteId in dropdown then only I am able to get the defaultDimension related to that siteId.
Is their any way to save the record in code itself as soon as I select a siteId in dropdown. after that I can get the reference of SiteId selected.
[ExtensionOf(tableStr(CustInvoiceTable))] final class HSHTCustInvoiceTable_Extension { public void modifiedField(FieldId _fieldId) { CustInvoiceTable custInvoiceTable; InventSiteId inventSiteId; next modifiedField(_fieldId); switch(_fieldId) { case fieldNum(CustInvoiceTable,HSHTSiteId) : inventSiteId = CustInvoiceTable::findRecId(this.RecId).HSHTSiteId; this.DefaultDimension = DimensionDefaultFacade::serviceMergeDefaultDimensions(custInvoiceTable.DefaultDimension, InventSite::find (inventSiteId).DefaultDimension); } } }
Select statement will not work for table buffer if the record is not yet saved. Can you comment line#12 and try using this.HSHTSiteId instead of custInvoiceTable.HSHTSiteId in Line#15 in CoC method.
Hi Andre,
I have wrote Onmodifiedfield event handler on table as you suggested:
[DataEventHandler(tableStr(CustInvoiceTable), DataEventType::ModifiedField)] public static void CustInvoiceTable_onModifiedField(Common sender, DataEventArgs e) { ModifyFieldEventArgs event = e as ModifyFieldEventArgs; CustInvoiceTable custInvoiceTable = sender as CustInvoiceTable; FieldId _fieldId = event.parmFieldId(); switch(_fieldId) { case fieldNum(CustInvoiceTable,HSHTSiteId): custInvoiceTable.DefaultDimension = DimensionDefaultFacade::serviceMergeDefaultDimensions(custInvoiceTable.DefaultDimension, InventSite::find (custInvoiceTable.HSHTSiteId).DefaultDimension); } }
I am passing custInvoiceTable.HSHTSiteId in find method in 13th line to find corresponding defaultDimension, but this field is null.
How can I fetch the value selected in HSHTSiteId lookup field using select statement in Event Handler to pass it in find method. I used Select custInvoiceTable; but while creating a new freetextInvoice, this HSHTSiteId value I selected is not stored in database yet, then how it will fetch using select statement.
I tried COC for modifiedfield method as well:
[ExtensionOf(tableStr(CustInvoiceTable))] final class HSHTCustInvoiceTable_Extension { public void modifiedField(FieldId _fieldId) { CustInvoiceTable custInvoiceTable; next modifiedField(_fieldId); switch(_fieldId) { case fieldNum(CustInvoiceTable,HSHTSiteId) : select firstonly custInvoiceTable where custInvoiceTable.OrderAccount == this.OrderAccount; info(strFmt("SiteId : %1",custInvoiceTable.HSHTSiteId)); this.DefaultDimension = DimensionDefaultFacade::serviceMergeDefaultDimensions(this.DefaultDimension, InventSite::find (custInvoiceTable.HSHTSiteId).DefaultDimension); } } }
but this info returns nothing, how can we fetch the value selected in HSHTSiteId field.
Thanks,
Rahul
Hi Rahul,
I would suggest writing an event handler on the table instead of acting on the form control. In case a user would add controls as a personalization, it will not execute the coding.
Besides, the coding you used now will not work anyway.
1) The sender is the form control. Now with coding, you try to get the formRun and then again the formcontrol SiteID.
2) With the newly found form control, you are not checking if a value is provided, but if the formstring control existst or not.
3) You are selecting a CustInvoiceTable, but you are not providing any ranges to retrieve which exact record. For sure this is not the record which is active on the form.
The best would be creating a event handler method for the onModifiedField event on the table CustInvoiceTable.
Hi Mohit,
I have tried above code you suggested but not working, I debug the code & found that the value I am passing inside find method (InventSite::find(custInvoiceTable.HSHTSiteId).DefaultDimension;) is actually null. before this I have used select custInvoiceTable but the value for HSHTSiteid is initially null at the time of creating the free text Invoice.
then How can I fetch the HSHTSiteId value for passing in find method bcz value is null in database itself.
Thanks
Rahul
Hi Rahul, If I understood your requirement correctly, you want to replace Default Dimension not merge it. Please try below code.
if (siteID) { custInvoiceTable.DefaultDimension = InventSite::find(custInvoiceTable.HSHTSiteId).DefaultDimension; }
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,836
Most Valuable Professional
nmaenpaa
101,156