The CreatorCon Call for Content is officially open! Get started here.

Disable the contractor accounts after 90 days of creation

Devika3
Tera Guru

Hi All,

We have a requirement to disable the contractor accounts after 90 days of creation.

After 90 days of account creation we need to send a notification to the manager . If the manager replies for extending the access we need to extend the access, else we need to submit the disable account form for disabling the account.

 

We can create a scheduled job for sending the notification to the manager after 90 days, but how can we find out whether the manager replies or not and how can we submit the disable form automatically.

 

Please guide me if anyone has an idea on this.

 

Any help is appreciated.

 

Regards,

Devika.

3 REPLIES 3

Fazal Mohammad
ServiceNow Employee
ServiceNow Employee

Hi @Devika3 

Please find the below approach:
Q1 : How can we find out whether the manager replies or not?
Ans: 

sendNotification: function(
        message,
        recipientId,
        targetId,
        targetTable,
        triggeredById
    ) {
        var notificationGR = new GlideRecord("ui_notification_inbox");
        notificationGR.setValue("recipient", recipientId);
        notificationGR.setValue("route", NOTIFICATION_ROUTE_SYS_ID); //this route should lead to ask for extend access or not
        notificationGR.setValue("status", "new");
        notificationGR.setValue("target", targetId); //userId
        notificationGR.setValue("target_table", targetTable); //userTable
        notificationGR.setValue("triggered_by", triggeredById);
        var payload = {
            "changes": {
                "custom": {
                    "displayValue": message,
                    "fieldLabel": "",
                    "value": ""
                }
            }
        };
        notificationGR.setValue("payload", JSON.stringify(payload));
        notificationGR.insert();
    }

For reference, check this route /sys_notification.do?sys_id=bdaa10360f3110105605539ac4767e12&sysparm_view=

 

I didn't quite get your second question : How can we submit the disable form automatically?

Please mark this answer helpful and accept solution, if it worked for you.

 

Thanks

Fazal

 

 

 

Hi Fazal,

Thanks for your reply.

Do we need to use this script in scheduled job?? or need to create an inbound. If we have to create an inbound , how can we establish the connection between the scheduled job(which is sending notification to manager) and inbound action.

 

The second question is as below:

 

We have a catalog item 'Disable Network Access' , once we submit this form for a user which will disable the user profile in the system.

 

If there is no response from the manager, we need to submit the disable network access catalog item, for disabling the access for the contractor. Which will disable his account in the system.

 

So our final requirement is as below:

1. The user account should be expired after 90 days of creation

2. We have to send a notification to the manager before 15 days of account expiration

3. If the manager replies to extend the access , need to extend the access for 90 more days

4. If there is no response/ replies to disable the access, Need to submit the Disable Network access form for the user, which will disable his account access as per the existing workflow.

 

Regards,

Devika.

 

Fazal Mohammad 
 
 
Please let me know if you have any inputs for this.