diff --git a/Server-Side Components/Transform Map Scripts/Incident Priority Set on Insert Only/README.md b/Server-Side Components/Transform Map Scripts/Incident Priority Set on Insert Only/README.md new file mode 100644 index 0000000000..dec7119b2f --- /dev/null +++ b/Server-Side Components/Transform Map Scripts/Incident Priority Set on Insert Only/README.md @@ -0,0 +1,18 @@ +# Incident priority set on insert only + +## What this solves +Recurring imports often overwrite priority even after the service desk has triaged the ticket. This onBefore script sets priority only when a row is inserted. Updates pass through without touching priority. + +## Where to use +Attach to your Incident Transform Map as an onBefore script. + +## How it works +- Checks the Transform Map action variable for insert vs update +- On insert, computes priority from impact and urgency +- On update, does nothing to priority + +## References +- Transform Map scripts + https://www.servicenow.com/docs/bundle/zurich-integrate-applications/page/administer/import-sets/task/t_AddOnBeforeScriptToTransformMap.html +- Incident fields and priority logic + https://www.servicenow.com/docs/bundle/zurich-it-service-management/page/product/incident-management/concept/incident-fields.html diff --git a/Server-Side Components/Transform Map Scripts/Incident Priority Set on Insert Only/onBefore_set_priority_insert_only.js b/Server-Side Components/Transform Map Scripts/Incident Priority Set on Insert Only/onBefore_set_priority_insert_only.js new file mode 100644 index 0000000000..fc0c814ff2 --- /dev/null +++ b/Server-Side Components/Transform Map Scripts/Incident Priority Set on Insert Only/onBefore_set_priority_insert_only.js @@ -0,0 +1,19 @@ +// Transform Map onBefore script: set priority on insert, not on update +(function runTransformScript(source, map, log, target) { + try { + if (String(action).toLowerCase() !== 'insert') { + log.info('Priority unchanged on update for number: ' + (target.number || '(new)')); + return; + } + + var impact = Number(source.impact) || 3; // 1..3 typical + var urgency = Number(source.urgency) || 3; // 1..3 typical + + // Simple matrix: priority = impact + urgency - 1, clamped 1..5 + var p = Math.max(1, Math.min(5, (impact + urgency) - 1)); + target.priority = String(p); + log.info('Priority set on insert to ' + p); + } catch (e) { + log.error('Insert-only priority failed: ' + e.message); + } +})(source, map, log, target);