From 4719cc03837490ed4bf1b9725d75a686e56e5a6a Mon Sep 17 00:00:00 2001 From: claw0ry Date: Wed, 11 Dec 2024 13:56:52 +0100 Subject: fresh start --- ...anged_fields_in_server_scripts_in_servicenow.md | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 content/posts/get_changed_fields_in_server_scripts_in_servicenow.md (limited to 'content/posts/get_changed_fields_in_server_scripts_in_servicenow.md') diff --git a/content/posts/get_changed_fields_in_server_scripts_in_servicenow.md b/content/posts/get_changed_fields_in_server_scripts_in_servicenow.md new file mode 100644 index 0000000..7242639 --- /dev/null +++ b/content/posts/get_changed_fields_in_server_scripts_in_servicenow.md @@ -0,0 +1,36 @@ +--- +title: "Get changed fields in server scripts in ServiceNow" +description: "In ServiceNow you often write Business Rules or some other logic, based on fields that has been changed/updated. For the most part, this can be done via GUI, but sometimes you have to resort to some scripting." +date: 2021-08-17T10:04:06+02:00 +tags: ['servicenow', 'javascript'] +draft: false +--- + +In ServiceNow you often write Business Rules or some other logic, based on fields that has been changed/updated. For the most part, this can be done via GUI, but sometimes you have to resort to some scripting. If you ever need to get which fields has been changed/updated, e.g in an advanced filter, this is how you check for it. + + + +```javascript +(function(current){ + var gru = GlideScriptRecordUtil.get(current); + + // Returns an arrayList of changed field elements with friendly names + var changedFields = gru.getChangedFields(); + + //Returns an arrayList of changed field elements with database names + var changedFieldNames = gru.getChangedFieldNames(); + + //Returns an arrayList of all change values from changed fields + var changes = gru.getChanges(); + + // Convert to JavaScript Arrays + gs.include('j2js'); + changedFields = j2js(changedFields); + changedFieldNames = j2js(changedFieldNames); + changeds = j2js(changes); + + gs.info("Changed Fields: " + JSON.stringify(changedFields)); + gs.info("Changed Field Names: " + JSON.stringify(changedFieldNames)); + gs.info("Changes: " + JSON.stringify(changes)); +})(current); +``` -- cgit v1.2.3