<h2>Scripts and engines execution order</h2><br/><div style="overflow-x:auto"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=UTF-8" /><meta name="copyright" content="(C) Copyright 2025" /><meta name="DC.rights.owner" content="(C) Copyright 2025" /><meta name="generator" content="DITA-OT" /><meta name="DC.type" content="reference" /><meta name="DC.title" content="Scripts and engines execution order" /><meta name="abstract" content="Scripts, assignment rules, business rules, workflows, escalations, and engines all take effect in relation to a database operation, such as insert or update. In many cases, the order of these events is important." /><meta name="description" content="Scripts, assignment rules, business rules, workflows, escalations, and engines all take effect in relation to a database operation, such as insert or update. In many cases, the order of these events is important." /><meta name="DC.subject" content="General Scripting, execution order of scripts and engines" /><meta name="keywords" content="General Scripting, execution order of scripts and engines" /><meta name="DC.creator" content="ServiceNow" /><meta name="DC.date.created" content="2023-08-03" /><meta name="DC.date.modified" content="2023-08-03" /><meta name="page-type" content="platform" /><meta name="DC.format" content="XHTML" /><meta name="DC.identifier" content="execution-order-scripts-engines" /><link rel="stylesheet" type="text/css" href="../../../CSS/commonltr.css" /><title>Scripts and engines execution order</title></head><body id="execution-order-scripts-engines"> <h1 class="title topictitle1" id="ariaid-title1">Scripts and engines execution order</h1> <div class="body refbody"><p class="shortdesc"><span class="ph">Scripts, assignment rules, business rules, workflows, escalations, and engines all take effect in relation to a database operation, such as insert or update. In many cases, the order of these events is important.</span></p> <div class="section" id="execution-order-scripts-engines__section_g1b_kpr_fbb"> <div class="p"><div class="note"><span class="notetitle">Note:</span> Client-based code that executes in the browser, using Ajax or running as JavaScript, will always execute before the form submission to the server.</div> </div> <div class="p">The order of execution is as follows:<ol class="ol" id="execution-order-scripts-engines__ol_qjj_rdj_dq"><li class="li">Before business rules: Scripts configured to execute before the database operation with an order less than 1000.</li><li class="li">Before engines. The following are not executed in any specific order:<ul class="ul" id="execution-order-scripts-engines__ul_qgd_vdj_dq"><li class="li">Approval engine (for task and sys_approval_approver tables)</li><li class="li">Assignment rules engine (for task tables)</li><li class="li">Data policy engine</li><li class="li">Escalation engine</li><li class="li">Field normalization engine</li><li class="li">Role engine - keeps role changes in sync with sys_user_has_role table (for sys_user, sys_user_group, sys_user_grmember, and sys_user_role tables)</li><li class="li">Execution plan engine (for task tables)</li><li class="li">Update version engine - creates version entry when sys_update_xml entry is written (for sys_update_xml table)</li><li class="li">Data lookup engine inserts or updates</li><li class="li">Workflow engine (for default workflows)</li></ul> </li><li class="li">Before business rules: Scripts configured to execute before the database operation with an order greater than or equal to 1000.</li><li class="li">The data base operation (insert, update, delete).</li><li class="li">After business rules: Scripts configured to execute after the database operation with an order less than 1000.</li><li class="li">After engines. The following are not executed in any specific order:<ul class="ul" id="execution-order-scripts-engines__ul_ck4_h2j_dq"><li class="li">Label engine</li><li class="li">Listener engine</li><li class="li">Table notifications engine</li><li class="li">Role engine - keeps role changes in sync with sys_user_has_role table (for sys_user, sys_user_group, sys_user_grmember and sys_user_role tables)</li><li class="li">Text indexing engine</li><li class="li">Update sync engine</li><li class="li">Workflow engine (for deferred workflows)</li><li class="li">Trigger engine (for all <span class="ph">Flow Designer</span> flows)</li></ul> </li><li class="li">Email notifications. The following are executed based on the weight of the notification record:<ul class="ul" id="execution-order-scripts-engines__ul_rgj_n2j_dq"><li class="li">Notifications sent on an insert, update, or delete</li><li class="li">Event-based notifications</li></ul> </li><li class="li">After business rules (Only active records). Scripts configured to execute after the database operation with an order greater than or equal to 1000.</li></ol> </div> </div> </div> </body></html></div>