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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Time out error while running test on Custom Script for zero downtime package

(0) ShareShare
ReportReport
Posted on by 59

Ok so I have a custom field in the extension of SalesTable. I have to update the value of the field across the whole table. So I used this code.

public static void main(Args _args)
   {
       try
       {
           str sql = @"
UPDATE SalesTable
SET EVS_TERMSENUM = 0 WHERE dataareaid = ‘sc’
";

           Evs_SalesTableUpdateTerms obj = new Evs_SalesTableUpdateTerms();
           obj.ExecuteSQLQuery(sql);
           info("Records updated successfully");
       }
       catch(Exception::Error)
       {
           ttsabort;
           info(strFmt("error : %1", infolog.text()));
       }
   }

   public void ExecuteSQLQuery(str sql)
   {
       Connection                      connection = new Connection();
       Statement                       statement;
       ResultSet                       resultSet;
       SqlStatementExecutePermission   perm;

       perm = new SqlStatementExecutePermission(sql);
       perm.assert();
       statement = connection.createStatement();
       statement.executeUpdate(sql);
   }

But when I created the package, uploaded it on Custom Scripts, and Ran Test after approving it, i got this error.

[8/4/2026 10:48:31 am] Test run started
[8/4/2026 10:53:36 am] Exception has been thrown by the target of an invocation.
[8/4/2026 10:53:36 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/4/2026 10:53:41 am] Infolog: 
Cannot execute the required database operation.
A time-out occurred in the database while the query was executing.
<Scrubbed Direct Sql query>
[8/4/2026 10:53:41 am] Completed


Can someone help kindly.

Categories:
I have the same question (0)
  • Subra Profile Picture
    1,916 on at

    Hi @SA-15031413-0 

    Which environment you have been facing this issue?

    Could you please let me know is there any specific reason why you have using SQL statements in your custom script to update the sales table?

    Thanks,
    Subra

     

  • Suggested answer
    CU29070609-0 Profile Picture
    14 on at

    Hi @SA-15031413-0 
    The timeout is happening because your direct SQL UPDATE is trying to update all records in one single transaction, which exceeds the Custom Script execution time limit. Replace your direct SQL approach with update_recordset which is the recommended D365FO approach :

    update_recordset salesTable setting EVS_TERMSENUM = 0 where salesTable.dataAreaId == 'sc' && salesTable.EVS_TERMSENUM != 0;

    This is faster, avoids table locking, and will not cause a timeout. If SalesTable still times out due to large data volume, process it in smaller batches using RecId ranges to avoid locking and timeout. 
    Hope this helps ! ,Kindly mark this as the verified if it's helpful!
    Thanks .

  • SA-15031413-0 Profile Picture
    59 on at

    @Subra, The SQL approach is one I saw online (kindly let me know if there is a better approach, as You can't access Database for live environment directly), and I am on Production Live environment.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 287 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 282 Super User 2026 Season 1

#3
Anton Venter Profile Picture

Anton Venter 259 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans