Custom scripts

- create a new model containing only one Runnable class
- write code in main method of that class
- create deployable package from VS for that model
- upload package to System administration / Periodic tasks / Database / Custom scripts
- Second person to approve script
- First person to Validate / Test
- script will be executed with ttsabourt at the end
- check Details field with output of SQL statements and infolog information including all errors
- click Validate / Test validated
- click Run / Run
- validate that data was fixed by reviewing real data in D365FO
- click Finilize / Verify

class VKDataFix651
{
    /// <summary>
    /// Deleting odd transaction, which left from work which is not longer available in the system.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        InventTransOrigin   inventTransOrigin;
        InventTransRefId    workId = 'WRK086211';
        ItemId              itemId = '218612';

        if (curExt() != 'VK')
        {
            throw error("This script must run in the VK company!");
        }

        ttsbegin;
        while select forupdate inventTransOrigin
            where inventTransOrigin.ReferenceId == workId
               && inventTransOrigin.ReferenceCategory == InventTransType::WHSWork
               && inventTransOrigin.ItemId == itemId
        {
            inventTransOrigin.delete();
            info(strFmt('inventTransOrigin %1 deleted', inventTransOrigin.RecId));
        }
        ttscommit;

        select firstonly inventTransOrigin
            where inventTransOrigin.ReferenceId == workId
               && inventTransOrigin.ReferenceCategory == InventTransType::WHSWork
               && inventTransOrigin.ItemId == itemId;

        if (!inventTransOrigin)
        {
            info("Success");
        }
        else
        {
            warning("Failed");
        }
        
    }

}
Please be aware that this framework is designed to handle really small amount of data. The problem is that it start SQL trace - which logs every data update. So for thousands of records it will try to write thousands of entries to log - and this times out in UI. Obviously it will work correctly in DEV environment as it executes as a usual job, however it might fail in Tier-2 environments.


 

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags