web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Custom script failed to run in production environment

(3) ShareShare
ReportReport
Posted on by 41
Hi All,
 
 
I have created a custom script to be run in production environment. We have tested in lower environments like preprod and dev. There was no issue whatsoever. When the same script is being run in production. I get the below error.
 
[8/29/2025 11:54:08 am] Test run started
[8/29/2025 11:54:17 am] Exception has been thrown by the target of an invocation.
[8/29/2025 11:54:17 am]    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Dynamics.AX.Application.AppConsistencyCustomScriptFile.executeScript()
   at Dynamics.AX.Application.AppConsistencyCustomScriptStateChange.runScript()
   at Dynamics.AX.Application.AppConsistencyCustomScriptStateChange.process(Boolean _isTestRun)
[8/29/2025 11:54:23 am] SQL statement: UPDATE APPCONSISTENCYCUSTOMSCRIPT SET LOG='',RECVERSION=972777893,MODIFIEDDATETIME='2025-8-29',MODIFIEDBY='APP_D365_ADMIN02' WHERE ((RECID=5637173826) AND (RECVERSION=595582687))
[8/29/2025 11:54:23 am] SQL statement: UPDATE APPCONSISTENCYCUSTOMSCRIPT SET LOG='',RECVERSION=1691892766,MODIFIEDDATETIME='2025-8-29',MODIFIEDBY='APP_D365_ADMIN02' WHERE ((RECID=5637173826) AND (RECVERSION=972777893))
[8/29/2025 11:54:23 am] Completed
Categories:
I have the same question (1)
  • Suggested answer
    Adis Profile Picture
    5,693 Super User 2025 Season 2 on at
    Custom script failed to run in production environment
    Hi,
     
    On the first sight, I would assume that you have different parameters or data in Prod and Sandboxes. What I would do, is to copy PROD to a sandbox and then try to execute the script. 
     
    The developer who created the script should be able to tell you whats wrong or how to fix it. Once you fix it in the sandbox and everything works fine, then you can fix it in PROD.
     

    Kind regards, Adis

     

    If this helped, please mark it as "Verified" for others facing the same issue

    Keep in mind that it is possible to mark more than one answer as verified

  • Suggested answer
    Sagar121 Profile Picture
    689 on at
    Custom script failed to run in production environment
    Hi, 
     
    You should retry. Sometimes Custom script don't run at first go. 
     
    If this don't work then try to run script when no-one is using System.
  • André Arnaud de Calavon Profile Picture
    299,349 Super User 2025 Season 2 on at
    Custom script failed to run in production environment
    Hi,

    When reading the question, I do assume you are using the option for running custom scripts without downtime? Did you do the same in DEV and PREPROD? Note that some tables are restricted to be updated. Can you tell what exact tables and updates to them you are trying to execute?
  • Ethan Hunt Profile Picture
    41 on at
    Custom script failed to run in production environment
    The custom script was run in lower environment like prerod and Dev. I did not take downtime to run the script, It may be possible when no one using the preproduction environment when i was testing.  For prod environment users could be accessing it or some interface is interacting with the table.
    The Table that i want to update is a custom table. That table has no index, primary key is rec ID and validate field, validate methods are not added for that table.
  • Verified answer
    Sagar121 Profile Picture
    689 on at
    Custom script failed to run in production environment
    Can you please confirm if PreProd and PROD are on same code base and DB? Want to double confirm apart from your user other user might is approving this right ?
  • Ethan Hunt Profile Picture
    41 on at
    Custom script failed to run in production environment
    Q: Can you please confirm if PreProd and PROD are on same code base and DB? Want to double confirm apart from your user other user might is approving this right ?
     
    Ans: The preprod that i tested is not in same code base as Prod. There are multiple branches, the code i tested one of the branch.
     
     
  • Ethan Hunt Profile Picture
    41 on at
    Custom script failed to run in production environment
    This is the code.
     
    public class xyx
    {
        public static void main(Args _args)
        {
            XYZHeaderxyzSalesTable;
            XYZLine xyzSalesLine;
            xyzLineLog xyzLineLog;
            Counter updateCounter;
            boolean isErrored = false;
     
            if(curExt() != "xyz")
            {
                throw Error(strFmt("Script should be run in xyx, Not in %1", curExt()));
            }
     
     
            // Create a list to hold strings
            List xyzSOList = new List(Types::String);
            // Add strings to the list
            xyzSOList.addEnd("xyz");
     
            // Create an enumerator to loop through the list
            ListEnumerator xyzSOEnumerator = xyzSOList.getEnumerator();
            while (xyzSOEnumerator.moveNext())
            {
                SalesID salesOrderNumber = xyzSOEnumerator.current();
                select firstonly xyzSalesTable where xyzSalesTable.SalesOrderNumber == salesOrderNumber
            && xyzSalesTable.DataAreaId == 'xyz'
                    join xyzSalesLine where xyzSalesLine.SalesOrderNumber ==xyzSalesTable.SalesOrderNumber;
     
                select forupdate firstonly xyzLineLog where xyzLineLog.SalesOrder == xyzSalesLine.SalesOrderNumber;
                if(xyzLineLog)
                {
                    try
                    {
                        ttsbegin;
                        xyzLineLog.SalesLineRefRecId = xyzSalesLine.RecId;
                        xyzLineLog.update();
                        Info(strFmt("Sales order is updated %1 with recID %2", xyzLineLog.SalesOrder, xyzSalesLine.RecId));
                        updateCounter++;
                        ttscommit;
                    }
                    catch (Exception::Error)
                    {
                        isErrored = true;
                        Error("An error occured during upload.");
                    }
                }
            }
            if(!isErrored)
            {
                info(strFmt("Total number of records that were udpated is %1",updateCounter));
            }
        }
     
    }
  • Ethan Hunt Profile Picture
    41 on at
    Custom script failed to run in production environment
    I restored from Prod to tier 2 environment. When i ran the script, it failed again. With same error. 
    Could it be data issue?
     
  • Sagar121 Profile Picture
    689 on at
    Custom script failed to run in production environment
    Hi, 
     
    Possibly you are right. But I would say you can restore this Data in DEV Box and move code to normal runnable class(main) and debug it. 
  • Verified answer
    Ethan Hunt Profile Picture
    41 on at
    Custom script failed to run in production environment
    Saleslinerefrecid field was not in the live branch. 
    Appconsistency picked it up as an issue, but didnt tell there is a missing field.
     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,100

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 890 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 633 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans