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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Arithmetic operations in Insert_RecordSet

(3) ShareShare
ReportReport
Posted on by 12
Hi All,
 
I am trying to do Arithmetic operations " (SettleAmountCur-UtilizedCashDisc)" in Insert_RecordSet query. Below is the query I am trying but getting error "Invalid Token (". But it works fine in Update_RecordSet. Can't we do Arithmetic operations in Insert_RecordSet.?
 
insert recordset impBankAccCustVendTransSettle
(BankTransDataAreaId, BankTransRecId, Voucher, SettleAmountCur, UtilizedCashDisc, SettleAmountIncDisc)
select crosscompany
DataAreaId,
RecId,
Voucher
From bankAccTrans
where bankAccTrans. SyncedToImp == NoYes:: No
join impParameters
where impParameters.DataAreaId == bankAccTrans.DataAreaId
&& impParameters.ActivateSetup == NoYes:: Yes
join bankAccTable
where bankAccTable.AccountID == bankAccTrans.AccountId
&& !(bankAccTable.Name2 like "*-P")
&& bankAccTable.DataAreaId == bankAccTrans.DataAreald
join vendTrans
where vendTrans. Voucher bankAccTrans. Voucher
&& vendTrans. TransType == Ledger Trans Type:: Payment
&& bankAccTrans. DataAreaId = vend Trans.DataAreaId
join SettleAmountCur, UtilizedCashDisc, (SettleAmountCur-UtilizedCashDisc) from vendSettlement
where vendSettlement.offsetRecid = vendTrans. RecId
&& vendSettlement.DataAreaId == vendTrans.DataAreaId;
Categories:
I have the same question (0)
  • Suggested answer
    Anton Venter Profile Picture
    20,656 Super User 2026 Season 1 on at
    Hi,
     
    No, it's not possible. You can however do an update on the data after inserting the data.
     
    Insert recordset Microsoft Learn
  • Suggested answer
    Navneeth Nagrajan Profile Picture
    2,538 Super User 2026 Season 1 on at
     
    To add to what Anton mentioned, one can correct arithmetic operations in the update clause of the update_recordset section.
    Insert_recordset does not allow this operation to be performed because:
    - insert_recordset only support Direct field-to-field mapping and constants.
    - It does not allow computed expressions in the select list (for eg. something like SettleAmount - UtilizedAmt) in the select list. 
     
    Either of the two approaches you can adopt to achieve this requirement:
    1. Use temporary tables or a container with a computed value and then use insert_recordset from the temporary table. 
        //Snippet of code
        TmpTable tmp;
        //Query model to retrieve vendSettlement data
        {
             tmp.SettlemAmountCur = vendSettlement.SettleAmountCur;
             tmp.SettleAmountIncDisc = vendSettlement.SettleAmountCur - vendSettlement.UtitlizedCashDisc;
             tmp.insert();
        }
     
        //Considering a table like impBankAccCustVendTransSettle
        insert_recordset impBankAccCustVendTransSettle
       (<otherfieldslikeVoucher>..,SettleAmountCur,SettleAmountIncDisc)
        select <otherfieldslist>..,SettleAmountCur,UtilizedCashDisc from tmp;
     
     
     
    2. Instead of insert_recordset, use a loop and calculate the value in X++ code.
        //Snippet of code
        //Query model to trigger a join between VendSettlement with an inner join to bankAccountTrans
        Join between vendSettlement and bankAccountTrans
          {
                 ///Fetch values through table buffer.
                  impBankAccCustVendTransSettle.voucher = bankAccountTrans.Voucher;
                  impbankAccCustVendTransSettle.insert(); 
          }
     
    Alternatively an approach as mentioned below should work. Would use a query model instead of a long while select instead.
     
    while select crosscompany DataAreaId, RecId, Voucher from bankAccTrans
        where bankAccTrans.SyncedToImp == NoYes::No
        join impParameters
            where impParameters.DataAreaId == bankAccTrans.DataAreaId
            && impParameters.ActivateSetup == NoYes::Yes
        join bankAccTable
            where bankAccTable.AccountID == bankAccTrans.AccountId
            && !(bankAccTable.Name2 like "*-P")
            && bankAccTable.DataAreaId == bankAccTrans.DataAreaId
        join vendTrans
            where vendTrans.Voucher == bankAccTrans.Voucher
            && vendTrans.TransType == LedgerTransType::Payment
            && bankAccTrans.DataAreaId == vendTrans.DataAreaId
        join vendSettlement
            where vendSettlement.OffsetRecId == vendTrans.RecId
            && vendSettlement.DataAreaId == vendTrans.DataAreaId
    {
        impBankAccCustVendTransSettle.BankTransDataAreaId = bankAccTrans.DataAreaId;
        impBankAccCustVendTransSettle.BankTransRecId      = bankAccTrans.RecId;
        impBankAccCustVendTransSettle.Voucher             = bankAccTrans.Voucher;
        impBankAccCustVendTransSettle.SettleAmountCur     = vendSettlement.SettleAmountCur;
        impBankAccCustVendTransSettle.UtilizedCashDisc    = vendSettlement.UtilizedCashDisc;
        impBankAccCustVendTransSettle.SettleAmountIncDisc = vendSettlement.SettleAmountCur - vendSettlement.UtilizedCashDisc;
        impBankAccCustVendTransSettle.insert();
    }

     
     
    Hope this helps. Happy to answer questions, if any. 
  • Verified answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at
    The approach I'd recommend using a view. You'll have the calculation in a computed column and use the view as the data source of insert_recordset
     
    I wouldn't use any of the solutions suggested by Navneeth. They all use row-by-row insert, despite the fact that the question is about insert_recordset. The first suggestion is does use insert_recordset, but it still inserts rows one by one to the temporary table, which makes it even less efficient than inserting records one by one to the target table. Note that you could use RecordInsertList in all the cases to make it more efficient (but less efficient than insert_recordset).
  • Suggested answer
    venkateswarrao v Profile Picture
    377 on at
    Great responses from Anton, Navneeth, and Martin here. I'd like to add some practical nuance on when to use each approach, especially around performance.
    Martin's point about the VIEW approach is spot-on — it's the architecturally correct solution for batch operations. But I think it's worth breaking down all three with a clear decision framework:
     
    Why insert_recordset Doesn't Support Arithmetic:
    `insert_recordset` only supports direct field-to-field mapping and constants — no computed expressions. It's by design, because the statement is optimized for pure batch operations at the database level. update_recordset works differently; it evaluates expressions in the update context.
     
    Three Approaches — Pick Based on Your Scenario:
     
    1. POST-INSERT UPDATE (Simplest, Good for Most Cases)
    Best when: moderate data volumes, code clarity matters, the view doesn't exist yet
    x++
    insert recordset impBankAccCustVendTransSettle
    (BankTransDataAreaId, BankTransRecId, Voucher, SettleAmountCur, UtilizedCashDisc)
    select crosscompany DataAreaId, RecId, Voucher, SettleAmountCur, UtilizedCashDisc
    from bankAccTrans
    // ... all your joins
    ;
    // Calculate derived field immediately after
    update_recordset impBankAccCustVendTransSettle
    setting SettleAmountIncDisc = SettleAmountCur - UtilizedCashDisc;
    ```
     Fast batch insert + update
    No temp tables or views
    Easy to debug and maintain
     
    2. VIEW WITH COMPUTED COLUMN (Best Practice for Performance)

    Best when: large data volumes, the calculation is reusable, you need true batch efficiency
    Create a view with the computed column:
    ```x++
    // In your data model / view definition
    select DataAreaId, RecId, Voucher, SettleAmountCur, UtilizedCashDisc,
           (SettleAmountCur - UtilizedCashDisc) as SettleAmountIncDisc
    from vendSettlement;
    ```
    Then use `insert_recordset` directly from the view:
    ```x++
    insert recordset impBankAccCustVendTransSettle
    (BankTransDataAreaId, BankTransRecId, Voucher, SettleAmountCur, UtilizedCashDisc, SettleAmountIncDisc)
    select crosscompany DataAreaId, RecId, Voucher, SettleAmountCur, UtilizedCashDisc, SettleAmountIncDisc
    from vendSettlementView; // View handles the arithmetic
    ```
     True batch operation (database-level optimization)
     Calculation is part of the data model (reusable)
     Best performance for large volumes
     Requires creating/maintaining a view
     
    3. LOOP WITH INSERT (Row-by-Row — Use Only When Necessary)

    Best when: complex conditional logic, you need record-level validation/transformations
    ```x++
    while select crosscompany DataAreaId, RecId, Voucher from bankAccTrans
        // ... your joins
    {
        impBankAccCustVendTransSettle.BankTransDataAreaId = bankAccTrans.DataAreaId;
        impBankAccCustVendTransSettle.BankTransRecId = bankAccTrans.RecId;
        impBankAccCustVendTransSettle.Voucher = bankAccTrans.Voucher;
        impBankAccCustVendTransSettle.SettleAmountCur = vendSettlement.SettleAmountCur;
        impBankAccCustVendTransSettle.UtilizedCashDisc = vendSettlement.UtilizedCashDisc;
        impBankAccCustVendTransSettle.SettleAmountIncDisc = 
            vendSettlement.SettleAmountCur - vendSettlement.UtilizedCashDisc;
        
        impBankAccCustVendTransSettle.insert();
    }
    ```
    ✓ Full flexibility for complex logic
    ✗ Slowest option — row-by-row processing
    âš  Use RecordInsertList if you go this route to improve efficiency
     
    Quick Decision Tree:
    - Large volume + reusable calculation? → Use VIEW (Martin's approach)
    - Moderate volume + one-time need? → Use POST-INSERT UPDATE (simplest)
    - Need complex logic per row? → Use LOOP (but minimize usage)
     
    For your specific scenario with the vendSettlement joins, either approach 1 or 2 will work well. If this becomes a recurring load process, I'd lean toward the
    VIEW approach for true batch efficiency.
    Hope this helps! Feel free to reach out if you hit any issues with the implementation.
  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at
    When you use AI to generate a reply, please make sure you review the correctness of the result and disclose the use of AI (see Use AI responsibly section of Writing effective responses in the community).
     
    The AI did a decent job rephrasing the previous replies, but its idea of how to create a computed column (the second solution) is wrong. It would work if you're defining a view in SQL on your own, not when you're adding a computed column to a view created by F&O.
  • Deepak Agarwal Profile Picture
    8,624 on at
    Generally  I would not recommend to use long nested joins for insert recrod set. Instead of try options of View described by Martin. Looing at your query, seems you are using custom table, which gives you more room to play around it.  
  • David Samuel Profile Picture
    12 on at
    Thank You Anton, Navneeth, Martin, Venkateswarrao, Deepak
     
    I used Insert_RecordSet + Update_RecordSet and it works perfectly with accurate data.
     
    As suggested by Martin and Deepak.. i will try using Views as well.
     
    Thank you for all the suggestions.
  • André Arnaud de Calavon Profile Picture
    303,730 Super User 2026 Season 1 on at
    Thanks for your update. Would you mind to mark the tickbox Does this answer your question on the replies that helped you? That will change the status of the question to Answered which is helpful for other community members with the same question. 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 663

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 439 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 337 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans