diff --git a/Background Scripts/Updating a record in the sys_user table/readme.md b/Background Scripts/Updating a record in the sys_user table/readme.md new file mode 100644 index 0000000000..f2a9daa1af --- /dev/null +++ b/Background Scripts/Updating a record in the sys_user table/readme.md @@ -0,0 +1,9 @@ +# update a record in sys_user table + +If we use the command below to update a record, it can lead to a problem. + +grUser.get('grUser.get('62826bf03710200044e0bfc8bcbe5df9')'); + +If the record is not found in the table, the script will create a new one. + +To make sure we are updating and not inserting, it is better to wrap up the get method with an If statement. \ No newline at end of file diff --git a/Background Scripts/Updating a record in the sys_user table/script.js b/Background Scripts/Updating a record in the sys_user table/script.js new file mode 100644 index 0000000000..e483846890 --- /dev/null +++ b/Background Scripts/Updating a record in the sys_user table/script.js @@ -0,0 +1,11 @@ +var grUser = new GlideRecord('sys_user'); + +if (grUser.get('62826bf03710200044e0bfc8bcbe5df9')) { + grUser.user_name = 'test.user'; + grUser.first_name = 'test'; + grUser.last_name = 'user'; + grUser.email = 'test.user@servicenow'; + grUser.update(); +} else { + gs.info('Record not found.'); +}