schedule a reindex?

johnwmmpls
Tera Contributor

I was wondering if anyone has figured out how to create a scheduled-job that performs a text-index (specifically sc_cat_item) on a table. Currently, I need to manually index each time after publishing new catalog items.

I have found the UI action + scripting that creates the "Regenerate Text Index" popup, however this does not translate directly into a scheduled-job, as it appears to require human interaction to push a button. The Wiki also references several Zing scheduled-jobs, but I they do not show any actual code.

Thanks!

1 REPLY 1

Chris_Hann
ServiceNow Employee
ServiceNow Employee

A re-index can be triggered by firing the


text_index.all
event for the table.

The below snippet should create the event with the appropriate parameters, and place it the text_index queue, the table will be re-indexed once the index job runs.


fireTableIndexEvent('sc_cat_item', 'myemail@example.com')

/**
* Fires an event which will cause the entire table to be re-indexed
*
* @param {string} tableName The table to be re-indexed
* @param {string} notifyEmailAddress The email address to be notified once the indexing is complete (optional)
*/
function fireTableIndexEvent(tableName, notifyEmailAddress) {
gs.eventQueue('text_index.all', null, tableName, notifyEmailAddress, 'text_index');
}


Try to schedule this at a time of low system usage, to minimise the chance of it affecting your end-users.

Rather than having this run every night, I typically include a re-index of sc_cat_item as part of the post-deploy activities when applying Update Sets to a target instance.