web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Parameter box is not getting refreshed and the current salesId is not getting stored

(0) ShareShare
ReportReport
Posted on by 34
Hello All,
I need to calculate the Advance Payment Amount for the lines of the selected salesId.
I have created a Menu item button for the dialog box and added two parameters, one of which is salesId, and the other is Advance Payment.
SalesId needs to be auto-filled when the button is clicked, and the Advance Payment will be filled manually.
And also, I have created the Contract class and the service class.
And then the calculated value will be stored in the Advance payment field in SalesLine. 
The calculation part and the storing of the value are working fine, but the problem is with auto-filling the salesId and refreshing the parameter box each time it is opened.
This is my code snippet:
public static void main(Args _args)
{
    AdvPayController controller = new AdvPayController();
    controller.parmClassName(classStr(AdvPayService));
    controller.parmMethodName(methodStr(AdvPayService, process));
    controller.parmArgs(_args);
    controller.parmDialogCaption("Advance Payment");
    controller.startOperation();
}
protected void initializeContract()
{
    //super();
    AdvPayContract contract = this.getDataContractObject();
     // Always reset the dialog fields
    contract.parmAdvancePay(0);
    Args localArgs = this.parmArgs();
    if (localArgs
        && localArgs.record()
        && localArgs.record().TableId == tableNum(SalesTable))
       {
          SalesTable salesTable = localArgs.record();
          contract.parmSalesId(salesTable.SalesId);
       }
 }
 protected void apply()
 {
 }
 public void run()
 {
      super();
      this.refreshSalesLines();
 }
 private void refreshSalesLines()
 {
      Args _argsLocal = this.parmArgs();
      if (_argsLocal
          && _argsLocal.caller()
          && _argsLocal.caller() is FormRun)
      {
         FormRun formRun = _argsLocal.caller();
         FormDataSource salesLineDss = formRun.dataSource(formDataSourceStr(SalesTable, SalesLine));
         if (salesLineDss)
         {
              salesLineDss.research(true);
              salesLineDss.refresh();
         }
      }
 }
 
Categories:
I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    302,532 Super User 2025 Season 2 on at
    Moved the question from the Dynamics 365 General to the Dynamics 365 Finance forum as the coding indicates it is about this product.
     
  • Suggested answer
    Diego Mancassola Profile Picture
    388 on at
    Hello, try to put your code into main (or initializeFromArgs but similar) method instead initializeContract (does not exists) just before the startOperation method. The button must have (or a parent item) the SalesTable as data source
  • Martin Dráb Profile Picture
    238,542 Most Valuable Professional on at
    What did you find where you debugged your code? Is initializeContract() ever called? I don't see any code doing so.
     
    The code for refresh is wrong, but before trying to fix it, tell us what execution modes you want to use and what do you want the refresh to do in each case. So far, your controller seem to support two asynchronous modes running on a batch server (ReliableAsynchronous and ScheduledBatch). So, you refresh the form immediately after create the batch, before it even executed, which isn't useful. When ithe batch completes, the user may be already working on something completely different, therefore even you found a technically feasible way, trying to refresh the form may be wrong. It's questionable whether the refresh logic makes sense with asynchronous processing at all. Let's see what business requirements you have for that.
     
    Moved from Integration, Dataverse, and general topics forum to Finance | Project Operations, Human Resources, AX, GP, SL forum.
     
     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 629 Super User 2025 Season 2

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 444 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 288 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans