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

Community site session details

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

Populate SalesOrderId from RetailTransactionTable

(0) ShareShare
ReportReport
Posted on by 198

Hi there, my requirement is populate SalesOrderId from RetailTransactionTable. I had created a new Table and added field called SalesOrder. I need to populate SalesOrderId from RetailTransaction table based on ChannelReferenceId. I just created a relation between RetailTransactionTable.ChannelReferenceId with MyTable.ChannelReferenceId. While selecting the ChannelReferenceID i need to get the SalesId but not happening for now. I tried with below attached code. Please find it and let me know the corrections/modifications for that. Thanks in advance

    
    public void updateStatus()
    {
    
    RetailTransactionTable retailTransactionTable ;
    MyTable                myTable;
    
    tts begin
    select * from retailTransactionTable where retailTransactionTable.ChannelReferenceId == myTable.ChannelReferenceId;

        retailTransactionTable.salesOrderId = myTable.SalesOrder;
        onlineOrderStatusTable.insert();
        
        ttscommit;
       
       }

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Populate SalesOrderId from RetailTransactionTable

    In your code, you initialize an empty "myTable" variable.

    Then you try to select RetailTransactionTable, where ChannelRefererenceId is the same than myTable.ChannelReferenceId. Since myTable buffer is empty, you are trying to select RetailTransactionTable where ChannelReferenceId is empty. Such record is not found.

    If you want to find RetailTransactionTable for a certain ChannelReferenceId, you need to specify some ChannelReferenceId in your select statement.

  • premK6969 Profile Picture
    198 on at
    RE: Populate SalesOrderId from RetailTransactionTable

    Hi Nikolaos, could you be more elaborate regarding your answer. Or can u pls modify the code i provided above as per your suggestions please? Thanks

  • nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Populate SalesOrderId from RetailTransactionTable

    Could you elaborate on your requirement? Are you trying to fill your table with ALL transactions from RetailTransactionTable, or insert one record in your table, based on a specific retail transaction?

    Thanks!

  • premK6969 Profile Picture
    198 on at
    RE: Populate SalesOrderId from RetailTransactionTable

    Yes, my requirement is ChannelReferenceId is automatically inserted into my table from annother job. I need to capture SalesOrderId from RetailTransactionTable based on that ChannelReferenceId.

    Or how can i populate SalesOrderId in RetailTransactionTable into myTable.SalesOrder ?

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Populate SalesOrderId from RetailTransactionTable

    Ok, so you already have ChannelReferenceId in your table before running this code.

    I also noticed a third table, onlineOrderStatusTable in your code. What is that one?

    In general your code doesn't even seem to compile.

    Let's go through your existing code one more time. I added comments to describe what it does on each line:

    public void updateStatus()
        {
        
        RetailTransactionTable retailTransactionTable ;
        MyTable                myTable; // myTable is introduced but never selected. So, all fields will be empty
        
        tts begin // Compiler error would occur. 
        
        // The next line will select retailTransactionTable where ChannelReference is empty
        select * from retailTransactionTable where retailTransactionTable.ChannelReferenceId == myTable.ChannelReferenceId;
    
            // Now you set empty value in retailTransactionTable.SalesId. Not much impact since it's anyway just an empty table buffer, and you never insert or update anything
            retailTransactionTable.salesOrderId = myTable.SalesOrder;
            
            // Finally, you insert "onlineOrderStatusTable". I assume this is some third table that you have introduced outside the code that you shared with us
            onlineOrderStatusTable.insert();
            
            ttscommit;
           
           }

    I'm still not sure about your requirement, your description is unfortunately a bit unclear.

    If I understand correctly, here are the facts and requirements:

    1) MyTable already contains records that have ChannelTransactionId

    2) You would like to copy SalesOrderId value from RetailTransactionTable to MyTable, using ChannelTransactionId as a key between these tables.

    Then the code would look something like this:

    MyTable myTable;
    RetailTransactionTable retailTransactionTable;
    
    ttsbegin;
    update_recordset myTable
            setting SalesOrder = retailTransactionTable.SalesOrderId
            join retailTransactionTable
            where retailTransactionTable.ChannelReferenceId == myTable.ChannelReferenceId;
    ttscommit;

    The question remains, why do you need to duplicate this data.

  • premK6969 Profile Picture
    198 on at
    RE: Populate SalesOrderId from RetailTransactionTable

    Hi Nikalos, the provided logic still not populating the expected SalesOrder from RetailTransactionTable. To clarify the questions you raised Please find the details mentioned below.

    1. I need to have SalesOrderId from RetailTransactionTable to update SalesStatus as per the business requirement before being entered into SalesTable

    2. onlineOrderStatusTable is  wrongly typed error pls ignore.

    3. The method you provided still not working and while debugging the recId is not generating from both the tables

    4. Please be informed that my requirement is to capture the SalesOrderId for that particular ChannelReferenceId in RetailTransactionTable and populate the same in myTable.SalesOrder. The provided code still not doing the work for me

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Populate SalesOrderId from RetailTransactionTable

    3. Not sure what you mean by "recId is not generating". This code is supposed to update records, not generate recIds or new records.

    4. How about this code, does it work? 

    ttsbegin;
    while select forupdate myTable
    {
        info(strFmt("MyTable.ChannelReferenceId is %1",   myTable.ChannelReferenceId));
        select firstonly  retailTransactionTable 
            where retailTransactionTable.ChannelReferenceId == myTable.ChannelReferenceId;
            
            if (retailTransactionTable)
            {
                info(strFmt("Retail transaction table found, Sales order number %1", retailTransactionTable.SalesOrderId));
                myTable.SalesOrder = retailTransactionTable.SalesOrderId;
                myTable.update();
            }
    }
    ttscommit;

  • premK6969 Profile Picture
    198 on at
    RE: Populate SalesOrderId from RetailTransactionTable

    Hi Nikalos, now am getting an error like record has never selected for update. Could you please look into the code which you provided before. Is there any corrections for that ?

    update_recordset myTable

           setting SalesOrder = retailTransactionTable.SalesOrderId

           join retailTransactionTable

           where retailTransactionTable.ChannelReferenceId == myTable.ChannelReferenceId;

    Do i need to add any insert or update call for that to work ? Thanks

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Populate SalesOrderId from RetailTransactionTable

    No, you don't need to add any insert or update call. With update_recordset you can update many records with just one database call: docs.microsoft.com/.../update-recordset

    However to keep it simple, could you please first try the code that I shared in my previous reply. And please let me know the result. Once it's working, you can work on optimizing the performance, and perhaps moving to update_recordset approach.

  • Suggested answer
    premK6969 Profile Picture
    198 on at
    RE: Populate SalesOrderId from RetailTransactionTable

    Thanks for the suggestion. That worked for me. 

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,850

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 519 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans