Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Calling itemId modified method

Posted on by 258
Hi,
 
I created a field on SalesQuotationLine. When filled, then I want to auto populate ItemId based on some logic.
 
At first, i wrote the code on the modified field of the table to auto populate itemId and it worked. But the other fields that gets populated automatically when filling the ItemId manually weren't filled (like salesCategory, procurment category..etc)
 
So in the modified field method, after filling the ItemId, i called this.modified(fieldNum(SalesQuotationLine,ItemId));
 
But it still didn't work. Then i noticed there is code on the modified method of itemId on the formDatasource itself.
 
So I moved my auto populating code to the formDatasource level instead of table level and called the modified method of the formDatasource. And indeed, it started filling itemId and the other fields when filling this new field. But somehow it cleared the new field that i fill (it seems there is code that clears the line when calling the modified method of the form datasource) so i had to store the original value of the new field and fill it again after calling the modified method. Is there another way?
 
[ExtensionOf(FormDataFieldStr(SalesQuotationProjTable, SalesQuotationLine, NewField))]
 final class SalesQuotationLineFDS_NewField_Extension
 { 
 public void modified()
 { 
 FormDataObject formDataObject = any2Object(this) as formDataObject;
 FormDataSource formDataSource = formDataObject.datasource();
 SalesQuotationLine salesQuotationLine = formDataSource.cursor();

 NewField newField = salesQuotationLine.NewField;
 
next modified();

 formDataSource.object(fieldNum(salesQuotationLine, ItemId)).modified();
 
salesQuotationLine.NewField = newField; 

 }
}
 
 
Categories:
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 229,426 Most Valuable Professional on at
    Calling itemId modified method
    If you're sure that keeping NewField value even after resetting the quotation line is the right approach, create an extension of SalesQuotationTableForm.resetSalesQuotationLine(), remember the value before next and put it to _salesQuotationLine again after next. I found this code by looking inside reReadSalesQuotationLine(); you should have done that too to understand the current logic and to be able to design a solution.
     
    Regarding element, you can use it in data source and data source fields extensions to access form variables, including those automatically created for data sources or so. For example, element.vendAdvanceInvoiceTable gives you the current record of VendAdvanceInvoiceTable data source.
  • CU04051814-0 Profile Picture
    CU04051814-0 258 on at
    Calling itemId modified method
    Hi Martin,

    where to use "element" can you please explain further?
    ​​​​​​​
    Also that's the code causing it, but i can't skip it that's why i assigned the value again after calling the modified method.
    but i wanted to see if there's a better approach
  • Martin Dráb Profile Picture
    Martin Dráb 229,426 Most Valuable Professional on at
    Calling itemId modified method
    If I was you, I would debug ItemId.modified() to see where the value disappears.
     
    By the way, you can simplify your code by accessing form variables through the element variable.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,946 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,426 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans