Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

How to update date field using update_recordset in D365FO

(0) ShareShare
ReportReport
Posted on by 171
Hi Team,
 
Using update_recordset i am updating the date.
Below code i am using.
public static void postGetStagingData(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution)    {        TestStaging    testStaging;               update_recordset testStaging            setting RequestedDeliveryDate = str2Date(subStr(testStaging.DateConvert, 1, 2) + '-' + subStr(testStaging.DateConvert, 3, 2) + '-' + subStr(testStaging.DateConvert, 5, 2), 321)                where testStaging.ExecutionId == _dmfDefinitionGroupExecution.ExecutionId &&                      testStaging.DefinitionGroup == _dmfDefinitionGroupExecution.DefinitionGroup;    }
testStaging.DateConvert = '230314';
 
But in testStaging.DateConvert is sowing null value.
 
If i use select statement and update the RequestedDeliveryDate, i can able to update.
 
Please let me know how to update RequestedDeliveryDate using  update_recordset.
  • Suggested answer
    How to update date field using update_recordset in D365FO
    Hi,
     
    update_recordset cannot use X++ methods. It does not translate them into the SQL ones, but calculates them immediately on the moment of start (once).
     
    to solve your task, you will have to code it as
    while select testStaging
    {
    // do your conversion logic
    testStaging.update();
    }
     
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,661 Super User 2024 Season 2 on at
    How to update date field using update_recordset in D365FO
    Hi,
     
    Reading the coding you shared is hard as the format lost the new lines. Anyway, you try to use the update_recordset calculating a field with values from the original records. I don't think the update_recordset will be feasible here. The generated SQL will literally replace the current known values. As the testStaging record in your coding is empty, it will use empty values to update using this command.
    It would be possible if you have a fixed date to update on several records.
  • Martin Dráb Profile Picture
    Martin Dráb 230,379 Most Valuable Professional on at
    How to update date field using update_recordset in D365FO
    Let me re-post your code.
    public static void postGetStagingData(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution)
    {
        TestStaging testStaging;
               
        update_recordset testStaging
            setting RequestedDeliveryDate = str2Date(subStr(testStaging.DateConvert, 1, 2) + '-' + subStr(testStaging.DateConvert, 3, 2) + '-' + subStr(testStaging.DateConvert, 5, 2), 321)
            where testStaging.ExecutionId == _dmfDefinitionGroupExecution.ExecutionId
               && testStaging.DefinitionGroup == _dmfDefinitionGroupExecution.DefinitionGroup;
    }
     
    I don't think that F&O is able to translate all the X++ functions (such as str2Date()) to T-SQL, so I indeed wouldn't expect it to work.
     
    Can't you parse the DateConvert value inside your entity?

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,661 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans