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 :
Microsoft Dynamics AX (Archived)

Query::Insert_recordset() error 'There is mismatch between source and target fields for insert_Recordset'

(0) ShareShare
ReportReport
Posted on by 129

Hi guys!

this is my first try to use the bulk insert from a Query result, Query::insert_recordset().

I made like the following example: 

https://axology.wordpress.com/2014/04/15/new-feature-in-ax-2012-r3-inserting-data-in-table-directly-from-query/

also I made sure every field from query is related to a field of the destination Tmp table by adding to the map

but it still throws an error ('There is mismatch between source and target fields for insert_Recordset.')

Would appreciate if someone can help.

*This post is locked for comments

I have the same question (0)
  • Douglas Noel Profile Picture
    3,907 on at

    Hi,

    I have no idea beside the following cause:

    Did you add a dataSource with an exist join dynamically to you query?

    There seems to be a flaw with insert_recordset in this situation.

    See KB/Issue 3626915

    Query insert recordset does not work with exists join queries dynamically created through code

    regards

    Douglas

  • Hugo Alves Profile Picture
    129 on at

    Thanks for replying Douglas.

    The KB you mentioned suggests a workaround that I tried but it does not solve the error.

    Indeed my query is changed by code, but previously generated on AOT.

  • Douglas Noel Profile Picture
    3,907 on at

    Hi Hugo,

    sorry no other idea at the moment. Is this reproducable with the newest kernel? The Query class itself resides deep dark in the kernel, so maybe something is fixed there?

    regards

    Douglas

  • Hugo Alves Profile Picture
    129 on at

    Initially i decided for Query just because i needed to change GroupBy field list dynamically. Perhaps due my query relations complexity and even aggregation function Sum i have to use it's not working.

    Finally i found a way to dynamically change my X++ Select statement which allows me to use 'Insert_recordset ... Select' and get better performance.

    Anyway, thanks for replying Douglas.

  • Community Member Profile Picture
    on at

    Hi All,

    if this problem will be raised,  you need to recall "clearAllFields()", f.e. 

    query = new Query(queryStr(myQuery));
    query.clearAllFields();

    otherwise u'll get that error

    Regards,

    Luca

  • Jerzy Profile Picture
    5 on at

    Hi,
    I have two similar problems.

    First is that i cannot use query::insert_recordset when the query uses aggregation and 'group by'.
    Can you explain how Do you dynamicly change select statement for insert_recordset () select ... statement?
    Or what I have to do to use "group by' i query for Query::insert_recordset

    Second problem:
    I create on form datasource method populte() data using query::insert_recordset(), but this work corectly only in init method on datasource.
    When I call this method again a have an error with duplicate column. (I see in error mesage that first column in map in insert statement is replaced by the last column.
    What can i do?

  • OlexandrPikalov Profile Picture
    on at

    Hi

    You can use insert_recordset with aggregation query if you specify aggregation function in fields mapping 

    E.g.

    fieldsMapping.insert(

    <Target Table fieldStr>,

    [ds.uniqueId(), strFmt("SUM(%1)", <Source table fieldStr>)])

    Worked for AX2012R3


    strF

    mt("SUM(%1)", fieldStr(InventTrans, CostAmountPhysical))

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 April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 28

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans