-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create add_more_tables_to_code_search.js
Initial commit
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Execute the following in the "Scripts - Background" console | ||
|
||
var grSearchGroup = new GlideRecord('sn_codesearch_search_group'); | ||
|
||
//get reference to default code search | ||
if (grSearchGroup.get('name', 'sn_codesearch.Default Search Group')) { | ||
var grDictionary = new GlideRecord('sys_dictionary'); | ||
var strSearchGroupSysID = grSearchGroup.getValue('sys_id'); | ||
var objArrayUtil = new ArrayUtil(); | ||
|
||
//retrieve all potential script-related fields from "global" scope | ||
grDictionary.addEncodedQuery( | ||
'sys_scope=global^' + | ||
'internal_type.nameINscript,condition,condition_string,script_plain,XML,script_server' + | ||
'^ORelement=reference_qual^ORelement=calculation' + | ||
'^nameNOT LIKEvar__m_' + | ||
'^NQelementSTARTSWITHscript' + | ||
'^ORelementLIKE_script' + | ||
'^internal_type.nameSTARTSWITHstring' + | ||
'^nameNOT LIKEvar__m_' + | ||
'^NQname=sys_variable_value^element=value' | ||
); | ||
|
||
grDictionary.query(); | ||
|
||
while (grDictionary.next()) { | ||
var grCodeSearch = new GlideRecord('sn_codesearch_table'); | ||
var strTable = grDictionary.getValue('name'); | ||
var strField = grDictionary.getValue('element'); | ||
|
||
grCodeSearch.addQuery('table', strTable); | ||
grCodeSearch.addQuery('search_group', strSearchGroupSysID); | ||
grCodeSearch.setLimit(1); | ||
grCodeSearch.query(); | ||
|
||
//for the respective table there is already a record available | ||
if (grCodeSearch.next()) { | ||
var arrFields = grCodeSearch.getValue('search_fields').split(','); | ||
|
||
arrFields.push(strField); | ||
|
||
grCodeSearch.setValue('search_fields', objArrayUtil.unique(arrFields).join(',')); | ||
grCodeSearch.update(); | ||
} | ||
// create a new record at table "sn_codesearch_table" | ||
else { | ||
grCodeSearch.initialize(); | ||
grCodeSearch.setValue('table', strTable); | ||
grCodeSearch.setValue('search_group', strSearchGroupSysID); | ||
grCodeSearch.setValue('search_fields', strField); | ||
grCodeSearch.insert(); | ||
} | ||
} | ||
} | ||
else { | ||
gs.error('Default search group "sn_codesearch.Default Search Group" not available!'); | ||
} |