misc
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| misc [01/22/2025 08:43] – johnsonjohn | misc [12/31/2025 05:41] (current) – removed johnsonjohn | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ======Miscellaneous====== | ||
| - | ---- | ||
| - | |||
| - | =====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); | ||
| - | |||
| - | } | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Data Copy from Column to Column===== | ||
| - | < | ||
| - | // Grab data from a column in a table and apply it to a new column in another table | ||
| - | // jwj0215 05/05/23 | ||
| - | // | ||
| - | var gr=new GlideRecord(' | ||
| - | |||
| - | gr.query(); | ||
| - | |||
| - | // | ||
| - | |||
| - | while(gr.next()) | ||
| - | { | ||
| - | var cs=new GlideRecord(' | ||
| - | cs.initialize(); | ||
| - | //as like bellow you can take values from gr and initialize them | ||
| - | //make sure that field type should be compatible | ||
| - | // cs.u_item=gr.sys_id; | ||
| - | // cs.u_stockroom=' | ||
| - | // cs.u_stock_number=100; | ||
| - | // cs.u_stock_limit=10; | ||
| - | cs.insert(); | ||
| - | } | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Defect Label Disable===== | ||
| - | < | ||
| - | // Defect Label Removal | ||
| - | |||
| - | (function executeRule(current, | ||
| - | |||
| - | // sys_id of the global label | ||
| - | var labelSysId = ' | ||
| - | // Color of the global label | ||
| - | var colorStr = '# | ||
| - | |||
| - | // Insert the Visual Task Board Label | ||
| - | var grBoardLabel = new GlideRecord(' | ||
| - | grBoardLabel.initialize(); | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.insert(); | ||
| - | |||
| - | })(current, previous); | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Feature Label Disable===== | ||
| - | < | ||
| - | // jwj0215 4.18.23 | ||
| - | // Feature Label Removal | ||
| - | |||
| - | (function executeRule(current, | ||
| - | |||
| - | // sys_id of the global label | ||
| - | var labelSysId = ' | ||
| - | // Color of the global label | ||
| - | var colorStr = '# | ||
| - | |||
| - | // Insert the Visual Task Board Label | ||
| - | var grBoardLabel = new GlideRecord(' | ||
| - | grBoardLabel.initialize(); | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.insert(); | ||
| - | |||
| - | })(current, previous); | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====GlideRecord CheetSheet===== | ||
| - | < | ||
| - | https:// | ||
| - | |||
| - | |||
| - | //Change state from New to Closed | ||
| - | var gr = new GlideRecord(' | ||
| - | gr.addQuery(' | ||
| - | gr.query(); | ||
| - | while(gr.next()) { | ||
| - | inc.comments=' | ||
| - | gr.state = 7; | ||
| - | gr.update(); | ||
| - | } | ||
| - | |||
| - | |||
| - | |||
| - | var gr = new GlideRecord(' | ||
| - | gr.query(); | ||
| - | while (gr.next()) | ||
| - | |||
| - | |||
| - | // JWJ0215 Find all incidents with a priority of 1 or 2 | ||
| - | var gr = new GlideRecord(' | ||
| - | gr.addQuery(' | ||
| - | gr.query(); | ||
| - | |||
| - | // JWJ0215 Find all active incident records and make them inactive | ||
| - | var gr = new GlideRecord(' | ||
| - | gr.addQuery(' | ||
| - | gr.query(); | ||
| - | while (gr.next()) { | ||
| - | gr.active = false; | ||
| - | gr.update(); | ||
| - | } | ||
| - | |||
| - | |||
| - | // JWJ0215 Find all inactive incidents and delete them all at once | ||
| - | var gr = new GlideRecord(' | ||
| - | gr.addQuery(' | ||
| - | gr.deleteMultiple(); | ||
| - | |||
| - | |||
| - | // JWJ0215 Find all inactive incident records and delete them one-by-one | ||
| - | var gr = new GlideRecord(' | ||
| - | gr.addQuery(' | ||
| - | gr.query(); | ||
| - | while (gr.next()) { | ||
| - | //Delete each record in the query result set | ||
| - | gr.deleteRecord(); | ||
| - | } | ||
| - | |||
| - | // JWJ0215 Find all active incidents and log a count of records to the system log | ||
| - | var gr = new GlideAggregate(' | ||
| - | gr.addQuery(' | ||
| - | gr.addAggregate(' | ||
| - | gr.query(); | ||
| - | var incidents = 0; | ||
| - | if (gr.next()){ | ||
| - | incidents = gr.getAggregate(' | ||
| - | gs.log(' | ||
| - | } | ||
| - | |||
| - | // JWJ0215 Find all active incidents and order the results ascending by category then descending by created date | ||
| - | var gr = new GlideRecord(' | ||
| - | gr.addQuery(' | ||
| - | gr.orderBy(' | ||
| - | gr.orderByDesc(' | ||
| - | gr.query(); | ||
| - | |||
| - | // JWJ0215 Find all incidents where the Short Description is empty | ||
| - | var gr = new GlideRecord(' | ||
| - | gr.addNullQuery(' | ||
| - | gr.query(); | ||
| - | |||
| - | // JWJ0215 Log the number of records returned by the query | ||
| - | var gr = new GlideRecord(' | ||
| - | gr.addQuery(' | ||
| - | gr.query(); | ||
| - | gs.log(' | ||
| - | |||
| - | // JWJ0215 Show all incidents that have the STATE of NEW. with incident number | ||
| - | var inc = new GlideRecord(' | ||
| - | inc.addQuery(' | ||
| - | inc.query(); | ||
| - | while (inc.next()) { | ||
| - | gs.print(' | ||
| - | } | ||
| - | function getState(tablename, | ||
| - | { | ||
| - | var ch = new GlideRecord(' | ||
| - | ch.addQuery(' | ||
| - | ch.addQuery(' | ||
| - | ch.query(); | ||
| - | if (ch.next()) | ||
| - | { | ||
| - | return ch.value; | ||
| - | } | ||
| - | } | ||
| - | |||
| - | // JWJ0215 Show the total number of closed incidents | ||
| - | var count=0; | ||
| - | var er = new GlideRecord(' | ||
| - | er.addEncodedQuery(" | ||
| - | er.query(); | ||
| - | while(er.next()) | ||
| - | { | ||
| - | count++ | ||
| - | gs.print(' | ||
| - | } | ||
| - | gs.print(' | ||
| - | |||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Idea Label Disable===== | ||
| - | < | ||
| - | // Idea disable 4993fe95975d5194b6a7fe021153af3b | ||
| - | |||
| - | |||
| - | (function executeRule(current, | ||
| - | |||
| - | // sys_id of the global label | ||
| - | var labelSysId = ' | ||
| - | // Color of the global label | ||
| - | var colorStr = '# | ||
| - | |||
| - | // Insert the Visual Task Board Label | ||
| - | var grBoardLabel = new GlideRecord(' | ||
| - | grBoardLabel.initialize(); | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.insert(); | ||
| - | |||
| - | })(current, previous); | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Multiple===== | ||
| - | < | ||
| - | JavaScript for ServiceNOW | ||
| - | |||
| - | javascript: gs.getUser().getRecord().getValue(' | ||
| - | |||
| - | javascript: var userPhone; var user = new GlideRecord(' | ||
| - | |||
| - | javascript: var userLoc; var user = new GlideRecord(' | ||
| - | |||
| - | javascript: var userfirst_name; | ||
| - | |||
| - | javascript: var userlast_name; | ||
| - | |||
| - | javascript: gs.getUser().getRecord().getValue(' | ||
| - | |||
| - | javascript: gs.getUser().getRecord().getValue(' | ||
| - | |||
| - | javascript: gs.getUser().getRecord().getValue(' | ||
| - | |||
| - | javascript: gs.getUser().getRecord().getValue(' | ||
| - | |||
| - | javascript: gs.getUser().getRecord().getValue(' | ||
| - | |||
| - | javascript: gs.getUser().getRecord().getValue(' | ||
| - | |||
| - | cmn_location | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Multiple 2===== | ||
| - | < | ||
| - | function resolveIncident() { | ||
| - | // Ensure that " | ||
| - | var assignedTo = g_form.getValue(' | ||
| - | if (!assignedTo) { | ||
| - | g_form.setMandatory(' | ||
| - | g_form.addErrorMessage(" | ||
| - | } else { | ||
| - | //Set the ' | ||
| - | g_form.setValue(' | ||
| - | g_form.setValue(' | ||
| - | g_form.setValue(' | ||
| - | |||
| - | gsftSubmit(null, | ||
| - | } | ||
| - | } | ||
| - | //Code that runs without ' | ||
| - | //Ensure call to server-side function with no browser errors | ||
| - | if (typeof window == ' | ||
| - | serverResolve(); | ||
| - | |||
| - | function serverResolve() { | ||
| - | // JWJ0215 Prevent Incident resolve if tasks are open | ||
| - | var gr = new GlideRecord(' | ||
| - | gr.addQuery(' | ||
| - | gr.addQuery(' | ||
| - | gr.query(); | ||
| - | if (gr.next()) { | ||
| - | gs.addInfoMessage((' | ||
| - | action.setRedirectURL(current); | ||
| - | } else { | ||
| - | current.incident_state = IncidentState.RESOLVED; | ||
| - | current.state = IncidentState.RESOLVED; | ||
| - | current.resolved_by = gs.getUserID(); | ||
| - | current.update(); | ||
| - | } | ||
| - | } | ||
| - | |||
| - | |||
| - | Workspace check workspace form button | ||
| - | function onClick() { | ||
| - | //Set the ' | ||
| - | g_form.setValue(' | ||
| - | g_form.setValue(' | ||
| - | g_form.setValue(' | ||
| - | |||
| - | // Call the UI Action and skip the ' | ||
| - | g_form.submit(g_form.getActionName()); | ||
| - | } | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Multiple 3===== | ||
| - | < | ||
| - | |||
| - | javascript: gs.getUser().getRecord().getValue(' | ||
| - | |||
| - | phone | ||
| - | javascript: var userPhone; var user = new GlideRecord(' | ||
| - | |||
| - | location | ||
| - | javascript: var userLoc; var user = new GlideRecord(' | ||
| - | |||
| - | setup_same_as | ||
| - | |||
| - | user_id | ||
| - | |||
| - | var myVar = g_form.getValue(' | ||
| - | |||
| - | g_form.setValue(' | ||
| - | |||
| - | function onChange(control, | ||
| - | if (isLoading || newValue == '' | ||
| - | return; | ||
| - | } | ||
| - | |||
| - | var request = g_form.getReference(' | ||
| - | |||
| - | function callback(request) { //reference is passed into callback as first arguments | ||
| - | |||
| - | g_form.setValue(' | ||
| - | |||
| - | } | ||
| - | |||
| - | |||
| - | javascript: var myVar = g_form.getValue(' | ||
| - | g_form.setValue(' | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Notification Email Includes Location===== | ||
| - | < | ||
| - | // Notification email to include ' | ||
| - | |||
| - | |||
| - | (function runMailScript(/ | ||
| - | /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action, | ||
| - | /* Optional GlideRecord */ event) { | ||
| - | |||
| - | var sLocationToOutput; | ||
| - | //If the user selected " | ||
| - | if (current.u_sd_location == " | ||
| - | { | ||
| - | //Use what they typed into the " | ||
| - | sLocationToOutput = current.u_sd_location_other; | ||
| - | } | ||
| - | // | ||
| - | else | ||
| - | { | ||
| - | sLocationToOutput = current.u_sd_location.u_name; | ||
| - | } | ||
| - | |||
| - | template.print(sLocationToOutput); | ||
| - | |||
| - | })(current, template, email, email_action, | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====PI Update===== | ||
| - | < | ||
| - | // JWJ0215 10.30.24 Evening | ||
| - | // Project Insight Update Script | ||
| - | // This script will get needed data from the ServiceNow Project Request (before approved for a project), and | ||
| - | // push the data to Project Insight. | ||
| - | |||
| - | (function executeRule(current, | ||
| - | var payload = {}; | ||
| - | |||
| - | // get user from user table | ||
| - | var gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.requested_for = gr.email.toString(); | ||
| - | } | ||
| - | // ***End get user*** | ||
| - | |||
| - | // Get Project Insight Records from the project Insight table **U_PROJECT_INSIGHT_RECORDS** | ||
| - | // get the sys id | ||
| - | var pigr = new GlideRecord(" | ||
| - | pigr.addQuery(" | ||
| - | pigr.query(); | ||
| - | |||
| - | if (pigr.next()) { | ||
| - | payload.u_project_insight_records_sysid = pigr.sys_id.toString(); | ||
| - | payload.u_project_insight_records_number = pigr.number.toString(); | ||
| - | payload.u_prioritization_group = pigr.u_prioritization_group.toString(); | ||
| - | payload.priority = pigr.priority.getDisplayValue(); | ||
| - | payload.u_expense = pigr.u_expense.toString(); | ||
| - | payload.u_project_request_status = pigr.u_project_request_status.toString(); | ||
| - | payload.short_description = pigr.short_description.toString(); | ||
| - | payload.description = pigr.description.toString(); | ||
| - | payload.u_estimated_hours = pigr.u_estimated_hours.toString(); | ||
| - | } | ||
| - | |||
| - | // Grab the Description from the task table ****************************************** | ||
| - | gr = new GlideRecord(" | ||
| - | gr.addQuery(' | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | gr.description.toString(); | ||
| - | } | ||
| - | |||
| - | |||
| - | |||
| - | gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.sponsor_manager_and_up_only_for_this_field = gr.email.toString(); | ||
| - | } | ||
| - | |||
| - | |||
| - | gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.contact_name = gr.name.toString(); | ||
| - | } | ||
| - | |||
| - | // which_location_is_the_project_for | ||
| - | gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.cost_center = gr.name.toString(); | ||
| - | } | ||
| - | |||
| - | |||
| - | // ***End get Project Insight Records*** | ||
| - | |||
| - | |||
| - | // below information is from the **SC_REQ_ITEM** table. | ||
| - | payload.sys_id = current.sys_id.toString(); | ||
| - | payload.u_project_approved_date = current.u_project_approved_date.toString(); | ||
| - | payload.number = current.number.toString(); | ||
| - | payload.u_project_type = current.u_project_type.toString(); | ||
| - | payload.request_created_on = current.variables.request_created_on.toString(); | ||
| - | payload.contact_s_phone_number = current.variables.contact_s_phone_number.toString(); | ||
| - | payload.what_is_the_problem_you_are_trying_to_solve = current.variables.what_is_the_problem_you_are_trying_to_solve.toString(); | ||
| - | |||
| - | // | ||
| - | // | ||
| - | |||
| - | |||
| - | var PI = new ProjectInsightScriptInclude(); | ||
| - | var res = PI.send(payload); | ||
| - | |||
| - | })(current, previous); | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Project GET===== | ||
| - | < | ||
| - | // JWJ0215 10.23.24 | ||
| - | // Project Insight Update Script | ||
| - | // This script will get needed data from the ServiceNow Project Request (before approved for a project), and | ||
| - | // push the data to Project Insight. | ||
| - | |||
| - | (function executeRule(current, | ||
| - | var payload = {}; | ||
| - | |||
| - | // get user from user table | ||
| - | var gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.requested_for = gr.email.toString(); | ||
| - | } | ||
| - | // ***End get user*** | ||
| - | |||
| - | // Get Project Insight Records from the project Insight table **U_PROJECT_INSIGHT_RECORDS** | ||
| - | // get the sys id | ||
| - | var pigr = new GlideRecord(" | ||
| - | pigr.addQuery(" | ||
| - | pigr.query(); | ||
| - | |||
| - | if (pigr.next()) { | ||
| - | payload.u_project_insight_records_sysid = pigr.sys_id.toString(); | ||
| - | payload.u_project_insight_records_number = pigr.number.toString(); | ||
| - | payload.u_prioritization_group = pigr.u_prioritization_group.toString(); | ||
| - | payload.priority = pigr.priority.getDisplayValue(); | ||
| - | payload.u_project_type = pigr.u_project_type.toString(); | ||
| - | payload.u_expense = pigr.u_expense.toString(); | ||
| - | payload.u_status = pigr.u_status.toString(); | ||
| - | payload.short_description = pigr.short_description.toString(); | ||
| - | payload.u_estimated_hours = pigr.u_estimated_hours.toString(); | ||
| - | } | ||
| - | |||
| - | gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.sponsor_manager_and_up_only_for_this_field = gr.email.toString(); | ||
| - | } | ||
| - | |||
| - | |||
| - | gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.contact_name = gr.name.toString(); | ||
| - | } | ||
| - | // which_location_is_the_project_for | ||
| - | gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.cost_center = gr.name.toString(); | ||
| - | } | ||
| - | // ***End get Project Insight Records*** | ||
| - | |||
| - | // below information is from the **SC_REQ_ITEM** table. | ||
| - | payload.sys_id = current.sys_id.toString(); | ||
| - | payload.number = current.number.toString(); | ||
| - | payload.request_created_on = current.variables.request_created_on.toString(); | ||
| - | payload.contact_s_phone_number = current.variables.contact_s_phone_number.toString(); | ||
| - | |||
| - | var PI = new ProjectInsightScriptInclude(); | ||
| - | PI.send(payload); | ||
| - | |||
| - | })(current, previous); | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Request Label Disable===== | ||
| - | < | ||
| - | // Request Disable | ||
| - | |||
| - | (function executeRule(current, | ||
| - | |||
| - | // sys_id of the global label | ||
| - | var labelSysId = ' | ||
| - | // Color of the global label | ||
| - | var colorStr = '# | ||
| - | |||
| - | // Insert the Visual Task Board Label | ||
| - | var grBoardLabel = new GlideRecord(' | ||
| - | grBoardLabel.initialize(); | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.insert(); | ||
| - | |||
| - | })(current, previous); | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Search MetaData for Sys_ID===== | ||
| - | < | ||
| - | // search metadata to find a specific sys_id (sys_metadata table) | ||
| - | // jwj0215 | ||
| - | // 6.27.23 | ||
| - | |||
| - | // Change sys id..... | ||
| - | var searchSys_id = " | ||
| - | | ||
| - | var y = new GlideRecord(' | ||
| - | |||
| - | | ||
| - | |||
| - | | ||
| - | |||
| - | | ||
| - | |||
| - | | ||
| - | |||
| - | { | ||
| - | | ||
| - | { | ||
| - | | ||
| - | | ||
| - | } | ||
| - | } | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | // JWJ0215 Show the total number of closed incidents | ||
| - | var count=0; | ||
| - | var er = new GlideRecord(' | ||
| - | er.addEncodedQuery(" | ||
| - | er.query(); | ||
| - | while(er.next()) | ||
| - | { | ||
| - | count++; | ||
| - | gs.print(' | ||
| - | } | ||
| - | gs.print(' | ||
| - | |||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====SNOW Pull from PI===== | ||
| - | < | ||
| - | /*MDP0722 10/23/2024 | ||
| - | Take project insight response and update ServiceNow | ||
| - | */ | ||
| - | |||
| - | try { | ||
| - | |||
| - | var r = new sn_ws.RESTMessageV2(' | ||
| - | // | ||
| - | |||
| - | var response = r.execute(); | ||
| - | var responseBody = response.getBody(); | ||
| - | var httpStatus = response.getStatusCode(); | ||
| - | gs.info(" | ||
| - | // | ||
| - | |||
| - | var responseObj = JSON.parse(responseBody); | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | for (var i = 0, len = responseObj.length; | ||
| - | |||
| - | var projectName = responseObj[i].Name; | ||
| - | var description = responseObj[i].description; | ||
| - | //var requestedFor = responseObj[i].requested_for; | ||
| - | var sysId = responseObj[i].sys_id; | ||
| - | var number = responseObj[i].number; | ||
| - | var prioritizationGroup = responseObj[i].u_prioritization_group; | ||
| - | var priority = responseObj[i].priority; | ||
| - | var expense = responseObj[i].u_expense; | ||
| - | var status = responseObj[i].u_status; | ||
| - | var shortDescription = responseObj[i].short_description; | ||
| - | var estimatedHours = responseObj[i].u_estimated_hours; | ||
| - | var sponsorMgrUp = responseObj[i].sponsor_manager_and_up_only_for_this_field; | ||
| - | var contactName = responseObj[i][" | ||
| - | var costCenter = responseObj[i][" | ||
| - | var createdOn = responseObj[i].request_created_on; | ||
| - | var contactPhone = responseObj[i][" | ||
| - | var dueDate = responseObj[i].due_date; | ||
| - | var piId = responseObj[i].u_project_insight_records_sysid; | ||
| - | var piNum = responseObj[i].u_project_insight_records_number; | ||
| - | var projectType = responseObj[i].u_project_type; | ||
| - | var complete = responseObj[i].Complete; | ||
| - | |||
| - | |||
| - | |||
| - | /* | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | // gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | */ | ||
| - | |||
| - | var name = sponsorMgrUp.split(' | ||
| - | var lname = name.split(' | ||
| - | gs.info(" | ||
| - | gs.info(" | ||
| - | |||
| - | //Query the u_project_insight table by sys_id and update fields for the matching sys_id | ||
| - | var gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.setLimit(100); | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | gs.info(" | ||
| - | |||
| - | if (status.length > 0) { | ||
| - | gr.u_status = status; | ||
| - | } | ||
| - | /* if (shortDescription.length > 0) { | ||
| - | gr.short_description = shortDescription; | ||
| - | }*/ | ||
| - | |||
| - | gr.u_estimated_hours = estimatedHours; | ||
| - | gr.u_complete = complete; | ||
| - | |||
| - | gr.update(); | ||
| - | } | ||
| - | var gr1 = new GlideRecord(" | ||
| - | gr1.addQuery(" | ||
| - | gr1.setLimit(100); | ||
| - | gr1.query(); | ||
| - | |||
| - | while (gr1.next()) { | ||
| - | // gs.info(" | ||
| - | |||
| - | if (dueDate.length > 0) { | ||
| - | gr1.due_date = dueDate; | ||
| - | // | ||
| - | // gs.info(" | ||
| - | } | ||
| - | gr1.u_complete = complete; | ||
| - | gr1.u_status = status; | ||
| - | gr1.u_hours = estimatedHours; | ||
| - | |||
| - | // gr1.update(); | ||
| - | |||
| - | var gr2 = new GlideRecord(" | ||
| - | // gr2.addQuery(" | ||
| - | gr2.addEncodedQuery(" | ||
| - | gs.info(" | ||
| - | gr2.setLimit(100); | ||
| - | gr2.query(); | ||
| - | |||
| - | if (gr2.next()) { | ||
| - | gs.info(" | ||
| - | var sponsorSysId = gr2.sys_id; | ||
| - | gr1.variables.sponsor_manager_and_up_only_for_this_field = sponsorSysId; | ||
| - | } | ||
| - | gr1.update(); | ||
| - | } | ||
| - | // | ||
| - | |||
| - | } | ||
| - | |||
| - | } catch (ex) { | ||
| - | var message = ex.message; | ||
| - | |||
| - | } | ||
| - | |||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====SNOW TO PI===== | ||
| - | < | ||
| - | // JWJ0215 11.01.24 - Last tested on 11.01 @ 12.34 | ||
| - | // Project Insight Update Script | ||
| - | // This script will get needed data from the ServiceNow Project Request (before approved for a project), and | ||
| - | // push the data to Project Insight. | ||
| - | |||
| - | (function executeRule(current, | ||
| - | var payload = {}; | ||
| - | |||
| - | // get user from user table | ||
| - | var gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.requested_for = gr.email.toString(); | ||
| - | } | ||
| - | // ***End get user*** | ||
| - | |||
| - | // Get Project Insight Records from the project Insight table **U_PROJECT_INSIGHT_RECORDS** | ||
| - | // get the sys id | ||
| - | var pigr = new GlideRecord(" | ||
| - | pigr.addQuery(" | ||
| - | pigr.query(); | ||
| - | |||
| - | if (pigr.next()) { | ||
| - | payload.u_project_insight_records_sysid = pigr.sys_id.toString(); | ||
| - | payload.u_project_insight_records_number = pigr.number.toString(); | ||
| - | payload.u_prioritization_group = pigr.u_prioritization_group.toString(); | ||
| - | payload.priority = pigr.priority.getDisplayValue(); | ||
| - | payload.u_expense = pigr.u_expense.toString(); | ||
| - | payload.u_project_request_status = pigr.u_project_request_status.toString(); | ||
| - | payload.short_description = pigr.short_description.toString(); | ||
| - | payload.description = pigr.description.toString(); | ||
| - | payload.u_status = pigr.u_status.toString(); | ||
| - | |||
| - | |||
| - | } | ||
| - | |||
| - | // Grab the Description from the task table ****************************************** | ||
| - | gr = new GlideRecord(" | ||
| - | gr.addQuery(' | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | gr.description.toString(); | ||
| - | } | ||
| - | |||
| - | |||
| - | |||
| - | gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.sponsor_manager_and_up_only_for_this_field = gr.email.toString(); | ||
| - | } | ||
| - | |||
| - | |||
| - | gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.contact_name = gr.name.toString(); | ||
| - | } | ||
| - | |||
| - | // which_location_is_the_project_for | ||
| - | gr = new GlideRecord(" | ||
| - | gr.addQuery(" | ||
| - | gr.query(); | ||
| - | |||
| - | if (gr.next()) { | ||
| - | payload.cost_center = gr.name.toString(); | ||
| - | } | ||
| - | |||
| - | |||
| - | // ***End get Project Insight Records*** | ||
| - | |||
| - | |||
| - | // below information is from the **SC_REQ_ITEM** table. | ||
| - | payload.sys_id = current.sys_id.toString(); | ||
| - | payload.u_project_approved_date = current.u_project_approved_date.toString(); | ||
| - | payload.number = current.number.toString(); | ||
| - | payload.u_project_type = current.u_project_type.toString(); | ||
| - | payload.request_created_on = current.variables.request_created_on.toString(); | ||
| - | payload.contact_s_phone_number = current.variables.contact_s_phone_number.toString(); | ||
| - | payload.what_is_the_problem_you_are_trying_to_solve = current.variables.what_is_the_problem_you_are_trying_to_solve.toString(); | ||
| - | payload.u_estimated_hours = current.u_hours.toString(); | ||
| - | |||
| - | |||
| - | var PI = new ProjectInsightScriptInclude(); | ||
| - | var res = PI.send(payload); | ||
| - | |||
| - | })(current, previous); | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Story Label Disable===== | ||
| - | < | ||
| - | // story disable | ||
| - | |||
| - | (function executeRule(current, | ||
| - | |||
| - | // sys_id of the global label | ||
| - | var labelSysId = ' | ||
| - | // Color of the global label | ||
| - | var colorStr = '# | ||
| - | |||
| - | // Insert the Visual Task Board Label | ||
| - | var grBoardLabel = new GlideRecord(' | ||
| - | grBoardLabel.initialize(); | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.setValue(' | ||
| - | grBoardLabel.insert(); | ||
| - | |||
| - | })(current, previous); | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Variable Finder===== | ||
| - | < | ||
| - | // Variable Finder for Catalog Item variables | ||
| - | // | ||
| - | // JWJ0215 09.28.24 | ||
| - | // This code will retrieve the Catalog Item Variables and organize them into containers | ||
| - | // | ||
| - | ClearUserLog(); | ||
| - | var CATALOG_ITEM_SYS_ID = ' | ||
| - | i, | ||
| - | currentVar, | ||
| - | fieldName = ' | ||
| - | varMap = {}, | ||
| - | | ||
| - | containerLevel = [], | ||
| - | item = GlideappCatalogItem.get(CATALOG_ITEM_SYS_ID), | ||
| - | grVariables = item.getVariables(); | ||
| - | |||
| - | //For every variable found... | ||
| - | while (grVariables.next()) { | ||
| - | |||
| - | var varName = grVariables.getValue(' | ||
| - | var varSid = grVariables.getValue(' | ||
| - | var varType = grVariables.type.getDisplayValue(); | ||
| - | var varQuestion = grVariables.getValue(' | ||
| - | var varActive = grVariables.getValue(' | ||
| - | |||
| - | if (varType === ' | ||
| - | containerLevel.push(varSid); | ||
| - | } else if (varType === ' | ||
| - | containerLevel.pop(); | ||
| - | } | ||
| - | currentContainer = varMap; | ||
| - | for (i = 0; i < containerLevel.length; | ||
| - | if (!currentContainer.hasOwnProperty(containerLevel[i])) { | ||
| - | currentContainer[containerLevel[i]] = {}; | ||
| - | } | ||
| - | currentContainer = currentContainer[containerLevel[i]]; | ||
| - | } | ||
| - | |||
| - | currentContainer[varSid] = new Variable(varName, | ||
| - | } | ||
| - | |||
| - | UserLog(JSON.stringify(varMap)); | ||
| - | |||
| - | function Variable(varName, | ||
| - | this.varName = varName; | ||
| - | this.varSid = varSid; | ||
| - | this.varType = varType; | ||
| - | this.varQuestion = varQuestion; | ||
| - | this.varActive = varActive; | ||
| - | this.varOrder = varOrder; | ||
| - | } | ||
| - | |||
| - | </ | ||
| - | ---- | ||
| - | |||
misc.1737564193.txt.gz · Last modified: by johnsonjohn
