Scheduled Job - Daily

MStritt
Tera Guru

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

6 REPLIES 6

OlaN
Giga Sage
Giga Sage

Hi,

This could be done with a Flow that runs on a schedule.

No coding required.

Providing a simple example below.

flow-update-records-daily.png

Manmohan K
Tera Sage

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();
}

  

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

 

Manmohan K
Tera Sage

@MStritt 

 

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...