misc
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| misc [01/22/2025 08:34] – created johnsonjohn | misc [01/22/2025 08:49] (current) – johnsonjohn | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ======Miscellaneous====== | ======Miscellaneous====== | ||
| + | ---- | ||
| + | |||
| + | =====Multiple GETs===== | ||
| + | < | ||
| + | //Get Current Role | ||
| + | gs.hasRole(' | ||
| + | |||
| + | //Get Current User | ||
| + | javascript: | ||
| + | gs.getUser().getUserByID(current.approver).hasRole(' | ||
| + | |||
| + | //Get Instance Name | ||
| + | gs.getProperty(" | ||
| + | |||
| + | //Get Instance URL | ||
| + | gs.getProperty(' | ||
| + | |||
| + | |||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | =====Record From Sys_ID===== | ||
| + | < | ||
| + | //This script searches all tables for the record identified by a given sys_id. | ||
| + | //It returns the table name where the sys_id was found, and links to the List View and Form View where the record //may be found. | ||
| + | //Specify the sys_id you are searching for. | ||
| + | |||
| + | var sysIdToFind = ' | ||
| + | |||
| + | //Invoke the search function. | ||
| + | FindRecGivenSysId(sysIdToFind); | ||
| + | |||
| + | function FindRecGivenSysId(sys_id) { | ||
| + | |||
| + | //Exclude any tables which are causing a problem for our search. | ||
| + | var tablesToExcludeFromSearch = [ | ||
| + | |||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | ]; | ||
| + | |||
| + | var baseTablesToSearch = new GlideRecord(' | ||
| + | var instanceURI = gs.getProperty(' | ||
| + | var recordFound = false; | ||
| + | var current; | ||
| + | var dict; | ||
| + | |||
| + | // | ||
| + | //Grab base tables, excluding text-indexing, | ||
| + | //Important to know: Records from Child tables will still be found in a search of the base table! | ||
| + | // There is no need to search child tables directly. | ||
| + | //The function getRecordClassName() can then be used to tell you the specific (child) table the | ||
| + | // record was found in. | ||
| + | baseTablesToSearch.addNullQuery(" | ||
| + | baseTablesToSearch.addQuery(" | ||
| + | baseTablesToSearch.addQuery(" | ||
| + | baseTablesToSearch.addQuery(" | ||
| + | baseTablesToSearch.query(); | ||
| + | |||
| + | while( baseTablesToSearch.next() ) { | ||
| + | // | ||
| + | |||
| + | current = new GlideRecord( baseTablesToSearch.name ); | ||
| + | |||
| + | //Find out if there is even a " | ||
| + | //skip it. | ||
| + | dict = new GlideRecord( ' | ||
| + | dict.addQuery(' | ||
| + | dict.addQuery(' | ||
| + | dict.queryNoDomain(); | ||
| + | if(!dict.next()) continue; | ||
| + | |||
| + | //Now search for the actual sys_id in the current table. | ||
| + | current.addQuery(' | ||
| + | //Prevent Query Rules from running, if allowed, as these may limit our results. | ||
| + | current.setWorkflow(false); | ||
| + | current.queryNoDomain(); | ||
| + | |||
| + | if( current._next() ) { | ||
| + | //We found the actual record by its sys_id value! | ||
| + | recordFound = true; | ||
| + | |||
| + | // | ||
| + | baseTablesToSearch.name); | ||
| + | |||
| + | // | ||
| + | |||
| + | var listViewURL = instanceURI + "/ | ||
| + | |||
| + | listViewURL = listViewURL.replace(" | ||
| + | |||
| + | listViewURL = listViewURL.replace(" | ||
| + | |||
| + | var listViewHTML = '<a href="' | ||
| + | |||
| + | |||
| + | |||
| + | var formViewURL = instanceURI + "/ | ||
| + | |||
| + | formViewURL = formViewURL.replace(" | ||
| + | |||
| + | formViewURL = formViewURL.replace(" | ||
| + | |||
| + | var directLinkHTML = '<a href="' | ||
| + | |||
| + | |||
| + | |||
| + | OutputToAll(" | ||
| + | |||
| + | OutputToAll(" | ||
| + | OutputToForm(listViewHTML); | ||
| + | OutputToForm(directLinkHTML); | ||
| + | OutputToLog(" | ||
| + | OutputToLog(" | ||
| + | |||
| + | //We found what we came for. No need to keep searching. | ||
| + | break; | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | if (! recordFound){ | ||
| + | |||
| + | OutputToAll(" | ||
| + | } | ||
| + | |||
| + | // | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | function OutputToAll(outputString){ | ||
| + | |||
| + | OutputToForm(outputString); | ||
| + | OutputToLog(outputString); | ||
| + | } | ||
| + | |||
| + | Function OutputToForm(outputString){ | ||
| + | gs.addInfoMessage(outputString); | ||
| + | } | ||
| + | |||
| + | function OutputToLog(outputString){ | ||
| + | //Log Prefix makes it much easier to find the statements we care about in the system log (table syslog). | ||
| + | |||
| + | var logPrefix = " | ||
| + | gs.print(logPrefix + outputString); | ||
| + | gs.log(logPrefix + outputString); | ||
| + | } | ||
| + | </ | ||
| ---- | ---- | ||
misc.1737563684.txt.gz · Last modified: by johnsonjohn
