Scheduled Job - Daily
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 10:57 AM
I'd like to run a scheduled job that runs nightly, that will look at all Contacts (customer_contact). The Contact will be deactivated (Active = false) if the following conditions are true. Below is the URL of the Conditions/query. I'll need help with sample code/script to use.
customer_contact_list.do%3Fsysparm_query%3Dlast_login_time%253Cjavascript%3Ags.beginningOfOneYearAgo()%255Eaccount!%253D58ba9ccb4fddb640873b69d18110c744%26sysparm_first_row%3D1%26sysparm_view%3Dcase

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 11:06 AM
Hi,
This could be done with a Flow that runs on a schedule.
No coding required.
Providing a simple example below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 11:08 AM
Hi @MStritt
You can use below script (add encoded query in script by copying from list view of contacts table)
// Build the encoded query for customer_contact
var encodedQuery = "add your query here"; //add your query in this line by copying from list view of contacts table
// Query the customer_contact table based on the encoded query
var contactGR = new GlideRecord('customer_contact');
contactGR.addEncodedQuery(encodedQuery);
contactGR.query();
// Loop through the contacts and deactivate them
while (contactGR.next()) {
contactGR.active = false;
contactGR.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 11:31 AM
Where do I start and end the query?
// Build the encoded query for customer_contact
var encodedQuery = "last_login_time%253Cjavascript%3Ags.beginningOfOneYearAgo()%255Eaccount!%253D58ba9ccb4fddb640873b69d18110c744%26sysparm_first_row%3D1%26sysparm_view%3Dcase"; //add your query in this line by copying from list view of contacts table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 11:37 AM
After building filter in contacts table, just copy query by right clicking on filter and add it directly in encodedQuery variable
Refer this link to understand how to copy query - https://docs.servicenow.com/bundle/utah-platform-user-interface/page/use/using-lists/task/t_GenEncod...