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 / Ferify

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");
        }
        
    }

}



 

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