Whenever a new user created after 1hr update the Onboarding status to 'Completed'

Omkarbh1997
Tera Expert

Hi, All

Whenever a new user created after 1hr update the Onboarding status to 'Completed'.

Onboarding status is a Choice field in user table.

and also trigger notification to the user.

1 ACCEPTED SOLUTION

sourav1999
Mega Guru

To achieve this, you can create a Scheduled Script Execution (Scheduled Job) in ServiceNow. Here are the steps:

 

1. Create a new Scheduled Job:

  • Navigate to System Definition > Scheduled Jobs.
  • Click New to create a new scheduled job.
  • Give it a name, for example, "Update Onboarding Status".

2. In the Run field, select "Periodically".

  • In the Repeat Interval field, enter "1 hour".

3. In the Script field, write a script to update the Onboarding status of newly created users. Here is a sample script:

javascript

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_created_on', '>=', gs.minutesAgo(60)); // get users created in the last hour

gr.query();

while(gr.next()) {

gr.u_onboarding_status = 'Completed'; // replace 'u_onboarding_status' with your actual field name gr.update();

}

 

4. Click Submit to save the scheduled job.

5. Create a new Email Notification:

- Navigate to System Policy > Email > Notifications.

- Click New to create a new notification.

- Give it a name, for example, "Onboarding Status Update Notification".

- In the Send when field, select "User: Onboarding status changes".

- In the Who will receive field, select "User".

- In the What it will contain field, write your message.

- Click Submit to save the notification.

 

6. Now, whenever a new user is created, the scheduled job will run every hour and update the Onboarding status to 'Completed'. The user will also receive a notification about this change.

 

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER

nowKB.com

View solution in original post

3 REPLIES 3

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Omkarbh1997 ,

 

Please try the below script in scheduled job script.

Schedule it periodically to run after 1 hour. In the script area paste below code. Remember to tweak the condition as per ur need.

 

(function() {

    var userGr = new GlideRecord('sys_user');

    userGr.addQuery('u_onboarding_status', 'IN', ['New', 'In Progress']); // Adjust statuses as needed

    userGr.addQuery('sys_created_on', '<', gs.hoursAgo(1));

    userGr.query();

 

    while (userGr.next()) {

        userGr.u_onboarding_status = 'Completed';

        userGr.update();

 

        // Send notification to the user

        gs.eventQueue('user.onboarding.completed', userGr, userGr.sys_id);

 

    }

})();

 

Thanks,

Danish

 

sourav1999
Mega Guru

To achieve this, you can create a Scheduled Script Execution (Scheduled Job) in ServiceNow. Here are the steps:

 

1. Create a new Scheduled Job:

  • Navigate to System Definition > Scheduled Jobs.
  • Click New to create a new scheduled job.
  • Give it a name, for example, "Update Onboarding Status".

2. In the Run field, select "Periodically".

  • In the Repeat Interval field, enter "1 hour".

3. In the Script field, write a script to update the Onboarding status of newly created users. Here is a sample script:

javascript

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_created_on', '>=', gs.minutesAgo(60)); // get users created in the last hour

gr.query();

while(gr.next()) {

gr.u_onboarding_status = 'Completed'; // replace 'u_onboarding_status' with your actual field name gr.update();

}

 

4. Click Submit to save the scheduled job.

5. Create a new Email Notification:

- Navigate to System Policy > Email > Notifications.

- Click New to create a new notification.

- Give it a name, for example, "Onboarding Status Update Notification".

- In the Send when field, select "User: Onboarding status changes".

- In the Who will receive field, select "User".

- In the What it will contain field, write your message.

- Click Submit to save the notification.

 

6. Now, whenever a new user is created, the scheduled job will run every hour and update the Onboarding status to 'Completed'. The user will also receive a notification about this change.

 

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER

nowKB.com

Hello, @sourav1999 

Thank You 

The solution you have given has run successfully.