Customization › Scripting

Script Debugger

Paused at a breakpoint in SuiteScripts/huzzle/hz_so_approval_ue.js · user event on Sales Order SO10142 · session 4f21-a09c

Execution log PausedUsage remaining 873
SuiteScripts/huzzle/hz_so_approval_ue.js
Line 24
1/**
2 * @NApiVersion 2.1
3 * @NScriptType UserEventScript
4 * @NModuleScope SameAccount
5 * Wexbourne ERP — sales order approval routing
6 */
7define(['N/record', 'N/search', 'N/runtime', 'N/log'], (record, search, runtime, log) => {
8
9 const TIER_LIMITS = { rep: 5000, manager: 25000, director: 100000 };
10
11 const getApprovalTier = (total, subsidiary) => {
12 const multiplier = subsidiary === 2 ? 1.15 : 1;
13 if (total <= TIER_LIMITS.rep * multiplier) return "rep";
14 if (total <= TIER_LIMITS.manager * multiplier) return "manager";
15 return "director";
16 };
17
18 const beforeSubmit = (context) => {
19 if (context.type === context.UserEventType.DELETE) return;
20
21 const so = context.newRecord;
22 const total = Number(so.getValue({ fieldId: "total" })) || 0;
23 const subsidiary = so.getValue({ fieldId: "subsidiary" });
24 const tier = getApprovalTier(total, subsidiary);
25
26 const customer = so.getValue({ fieldId: "entity" });
27 const onHold = search.lookupFields({
28 type: search.Type.CUSTOMER,
29 id: customer,
30 columns: ["custentity_hz_credit_hold"]
31 }).custentity_hz_credit_hold;
32
33 if (onHold) {
34 so.setValue({ fieldId: "orderstatus", value: "A" });
35 so.setValue({ fieldId: "memo", value: "Held — customer on credit hold" });
36 log.audit("Credit hold", "Order held for customer " + customer);
37 return;
38 }
39
40 so.setValue({ fieldId: "custbody_hz_approval_tier", value: tier });
41 so.setValue({ fieldId: "custbody_hz_approver", value: resolveApprover(tier) });
42
43 log.audit({
44 title: "Approval routed",
45 details: "total=" + total + " tier=" + tier
46 });
47 };
48
49 return { beforeSubmit };
50});
Paused — the next statement is line 24. Click the gutter to set a breakpoint.
Watches
ExpressionValue
total18420
number
subsidiary"2"
string
tier"manager"
string
customer"4471"
string
onHoldfalse
boolean
context.type"create"
string
runtime.getCurrentUser().id1042
number
runtime.getCurrentScript().getRemainingUsage()873
number
Call stack
  • getApprovalTierhz_so_approval_ue.js:24
  • beforeSubmithz_so_approval_ue.js:41
  • UserEventDispatcher.invokehz_runtime_bridge.js:88
  • RecordSubmitHandler.submithz_record_engine.js:214
Breakpoints
  • hz_so_approval_ue.js:12
    Condition: total > 10000
  • hz_so_approval_ue.js:24
    Condition: —
  • hz_so_approval_ue.js:39
    Condition: onHold === true
  • hz_invoice_ue.js:61
    Condition: —
MC