Skip to content

Background scripts #1069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 1, 2024
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.');
}
Loading