Skip to main content

Notifications

Announcements

No record found.

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

  • OlexandrPikalov Profile Picture
    on at
    RE: Query::Insert_recordset() error 'There is mismatch between source and target fields for insert_Recordset'

    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))

  • Jerzy Profile Picture
    5 on at
    RE: Query::Insert_recordset() error 'There is mismatch between source and target fields for insert_Recordset'

    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?

  • Community Member Profile Picture
    on at
    RE: Query::Insert_recordset() error 'There is mismatch between source and target fields for insert_Recordset'

    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

  • Hugo Alves Profile Picture
    129 on at
    RE: Query::Insert_recordset() error 'There is mismatch between source and target fields for insert_Recordset'

    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.

  • Douglas Noel Profile Picture
    3,905 on at
    RE: Query::Insert_recordset() error 'There is mismatch between source and target fields for insert_Recordset'

    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
    RE: Query::Insert_recordset() error 'There is mismatch between source and target fields for insert_Recordset'

    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,905 on at
    RE: Query::Insert_recordset() error 'There is mismatch between source and target fields for insert_Recordset'

    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

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 Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 48

#3
shanawaz davood basha Profile Picture

shanawaz davood basha 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans