Please let me know how can we implement below scenario in servicenow

mani55
Tera Contributor
we need to send an Notification to ask user with  rights to send a mail if he wants to keep the rights without any answer the access rights will be deactivated at the end of the month.
The mail must be sent first week of July and first week of November, if the user doesn't answer to Finance Team before the end of the month when they received the email, the  rights of the user are deactivated.
 
The first sending must start the first week of Nov 2024.
 
 
Please let me know how can we implement below scenario in ServiceNow
 
 
1 ACCEPTED SOLUTION

Hi @mani55 ,

 

You can schedule the job to run monthly on the first day of each month, and include the relevant logic in the script.

 

use below code -

var currentMonth = new GlideDateTime().getMonth(); // Get the current month (1-12)
// Check if the current month is July (7) or November (11)
if (currentMonth == 7 || currentMonth == 11) {
//Write your code under it
}

It will allow you to run your job only on 1st day of July and November month only.

 

Hope this help you

 

Regards

Moin

View solution in original post

4 REPLIES 4

ELMAHDI
Tera Expert

Hello @mani55 

 

Yes you can, Create a Scheduled Job for Email Notification .

 

thank you, please if you find this helpful don't forget to click on the helpful button 

 

mani55
Tera Contributor

How we can specified noveber1st week and july1st week

Hi @mani55 ,

 

You can schedule the job to run monthly on the first day of each month, and include the relevant logic in the script.

 

use below code -

var currentMonth = new GlideDateTime().getMonth(); // Get the current month (1-12)
// Check if the current month is July (7) or November (11)
if (currentMonth == 7 || currentMonth == 11) {
//Write your code under it
}

It will allow you to run your job only on 1st day of July and November month only.

 

Hope this help you

 

Regards

Moin

Moin Kazi
Kilo Sage
Kilo Sage

Hi @mani55 ,

 

To implement the notification scenario in ServiceNow, you can follow these steps:

1. Create a Notification

First, create a notification that will be sent to users with access rights.

  1. Navigate to System Notification > Email > Notifications.
  2. Click on New to create a new notification.
  3. Set the Name, e.g., "Access Rights Renewal Notification."
  4. Under the When to send tab:
    • Set the Type to "Email."
    • In the Send When section, select "Record inserted or updated."
  5. Under the Who will receive tab:
    • Add a condition to specify the users with rights (e.g., based on a specific role or access group).
  6. In the What it will contain tab, compose the email message. Include instructions on how to respond to the Finance Team and state that failure to respond will result in deactivation of access rights.

2. Scheduled Job for Notifications

To send notifications automatically in the first week of July and November, create a scheduled job.

  1. Navigate to System Definition > Scheduled Jobs.
  2. Click on New.
  3. Set the Name (e.g., "Access Rights Notification Scheduler").
  4. In the Run section, set the job to run Monthly and Day to 1.
  5. Set the First run date to the first week of November 2024.
  6. In the Script section, use the following code to send notifications:

 

 

var currentMonth = new GlideDateTime().getMonth(); // Get the current month (0-11)

// Check if the current month is July (6) or November (10)
if (currentMonth == 7 || currentMonth == 11) {
    var gr = new GlideRecord('sys_user'); // Adjust this to the correct user table if needed
    gr.addQuery('your_condition_here'); // Replace with your condition to find users with rights
    gr.query();

    while (gr.next()) {
        // Send notification for access rights renewal
        gs.eventQueue('access_rights_renewal', gr, null, null);
    }
}

 

3. Create an Event for Notifications

Create an event that will be triggered by the scheduled job to send out the notification.

  1. Navigate to System Policy > Events > Events.
  2. Click on New and create an event (e.g., "access_rights_renewal").

4. Response Handling

To manage user responses, create a separate table or use an existing one to log responses from users. You can also create a business rule to check for responses:

  1. Navigate to System Definition > Business Rules.
  2. Create a new business rule that triggers on the response record insert/update.
  3. In the business rule, check if a response was received. If not, schedule a job to deactivate access rights at the end of the month.

5. Deactivate Access Rights

To deactivate access rights, create a scheduled job or a business rule that checks if any user did not respond by the end of the month and then updates their access rights accordingly.

 

Hope this help to you.

 

Regards

Moin