Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Retrieve the selected sales order details from the SalesCopying form when the OK button is pressed

(2) ShareShare
ReportReport
Posted on by 40
Hi Team,
Seeking support for the following!!
 
I need to set the workerResponsible same as the Sales Order form in return sales order. To accomplish this, I extended the class below and attempted to retrieve the selected sales order details from the SalesCopying form (Return Sales Order) when the OK button is pressed. However, no records are being retrieved, and the SalesTable seems to be empty.
[ExtensionOf(formStr(SalesCopying))]
final class SalesCopying_Extension
{
    void  init()
    {
        next init();
    }
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormControlEventHandler(formControlStr(SalesCopying, OK), FormControlEventType::Clicked)]
    public  void OK_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        SalesId sid=salesTable.SalesId;

        FormRun formRun = sender.formRun() as FormRun;
        FormDataSource formDataSource;
        Common common; 

        formDataSource = formRun.dataSource(formDataSourceStr(SalesCopying, SalesTable));

        common = formDataSource.cursor();

        if (common)
        {
            str headerField1 = common.(fieldNum(SalesTable, SalesId));
            info(strFmt("Selected header: %1", headerField1));
        }
    }
}
 
Categories:
  • Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    Retrieve the selected sales order details from the SalesCopying form when the OK button is pressed
    Just look into the existing code.
     
    If you're extending SalesTable.initFromSalesTable(), the sales order to copy from is in salesTable variable, the new one in this variable.
     
    If you're extending SalesTableCopyFromSalesTable.copy(), the sales order to copy from is in sourceSalesTable variable and the new one in salesTable variable.
  • BibinTV Profile Picture
    40 on at
    Retrieve the selected sales order details from the SalesCopying form when the OK button is pressed

    Hi Martin, thank you. I followed the suggested solution, but I'm still having trouble retrieving the selected sales order from the grid. Could you please assist me with this? I was able to update a record successfully.

     
     public void copy()
        {
            next copy();
            str refId = SalesLine::find(salesTable.SalesId).InventTransIdReturn;
            str salesId = InventTransOrigin::findByInventTransId(refId).ReferenceId;
    
            salesTable.WorkerSalesResponsible=5637147530; //Need to set from the ref transaction
    
            this.updateHeader();
    
            info(strFmt("Ref Sales order Id: %1", this.salesTable.WorkerSalesResponsible));
            info(strFmt("Sales order Id: %1", salesId));
        }
      
  • Verified answer
    Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    Retrieve the selected sales order details from the SalesCopying form when the OK button is pressed
    Your approach to the design is wrong. You shouldn't blindly put your logic on the button click; you must analyze the standard logic and identify the right place to modify.
     
    The actual business logic for copying is in SalesCopying class; the entry point is the copy() method.
     
    You're talking about a header field, therefore you'll be interested in copyHeader(). When you look at its implementation, you'll find SalesTableCopyFromSource and its children. If you're interested on copying a sales order, then the relevant child is SalesTableCopyFromSalesTable. It simply calls SalesTable.initFromSalesTable() to copy the fields.
     
    Don't forget that you also have the debugger on hand; that can show you what exactly happens in standard code when you execute the process. 
     
    Moved from Integration, Dataverse, and general topics 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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,095 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans