├── .DS_Store ├── ui ├── .DS_Store ├── ui_scripts │ ├── monitorStatus_ngApp.js │ ├── monitorStatus_ngTemplates.js │ ├── monitorStatus_ngModel.js │ ├── monitorStatus_ngCtrl.js │ └── pdf_template.js ├── ui_actions │ ├── generateCategorieslist.js │ └── Clone.js ├── ui_macros │ ├── monitorTemplate.js │ ├── breakdownchart.js │ ├── scorecard.html │ ├── kpitable.html │ └── gauge.js └── ui_pages │ ├── monitorStatus_dashboard.html │ ├── highchart.js │ ├── po.js │ └── barchart.xml ├── images ├── .DS_Store └── excelsimulator.png ├── libraries ├── .DS_Store └── script_includes │ ├── userUtils.js │ ├── financeUtils.js │ ├── po_pdf.js │ ├── usefulUtils.js │ ├── chargeBack.js │ ├── FeedbackUtils.js │ ├── loanerCatServices.js │ ├── BVLoanercatServices.js │ ├── CompanyMatchAlgo.js │ ├── eventUtils.js │ ├── ContractSecurityUtils.js │ └── catalogservices.js ├── client_side ├── .DS_Store ├── client_scripts │ ├── hideOrderGuideVariables.js │ ├── idcreator.js │ ├── hideemptyvars.js │ ├── hideknowledgeicon.js │ └── Highlight_VIP_Caller.js ├── catalog_client_scripts │ ├── hideorderguidevar.js │ ├── loadrequestfor.js │ ├── ToDateChecker.js │ ├── InventoryLookup.js │ ├── FromDataChecker.js │ ├── openehelptext.js │ ├── CascadeEngine.js │ └── cascadevaranswers.js └── Calculated_Fields │ ├── calctotals.js │ └── Financials.js ├── server_side ├── .DS_Store ├── Background_Scripts │ ├── .DS_Store │ ├── updateScope.js │ ├── findReplace.js │ └── findAnywhere.js ├── Business_Rules │ ├── getcompanyid.js │ ├── usertableseperation.js │ ├── updaterequest.js │ ├── finduserrole.js │ ├── creatIdentifier.js │ ├── offboarding.js │ ├── Cross-reference.js │ ├── checklistIncomplete.js │ ├── orderCatalogItem.js │ ├── recover.js │ ├── populateChecklist.js │ ├── hideemptyvar.js │ └── Financials.js ├── list_control │ └── omitNew.js ├── mail_script │ ├── itemsummary.js │ └── request_approval.js ├── inbound_actions │ ├── parseTable.js │ ├── inserKb.js │ └── offBoarding.js └── script_actions │ └── KPI.js ├── update_sets ├── .DS_Store ├── kpi_manager │ ├── KPI app fron end.png │ └── README.md └── README.md ├── webservices ├── .DS_Store ├── rest_apis │ └── monitorStatus_restAPI.js └── outbound │ └── rest │ └── outbound.js ├── fix_scripts └── nuke.js ├── README.md ├── wf_scripts ├── currentrequestitem.js ├── replaceHtml.js ├── emaileventparam1.js ├── movevaluefromontasktoanother.js ├── findsupportgroup.js ├── employeeExists.js └── updateItem.js ├── notifications ├── banner.js ├── footer.js ├── itemapproval.js └── requestlevelApproval.js ├── scheduled_jobs ├── reminder.js ├── reports.js └── license.js └── acl_scripts └── statusUpdate.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonemking/servicenow/HEAD/.DS_Store -------------------------------------------------------------------------------- /ui/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonemking/servicenow/HEAD/ui/.DS_Store -------------------------------------------------------------------------------- /images/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonemking/servicenow/HEAD/images/.DS_Store -------------------------------------------------------------------------------- /libraries/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonemking/servicenow/HEAD/libraries/.DS_Store -------------------------------------------------------------------------------- /client_side/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonemking/servicenow/HEAD/client_side/.DS_Store -------------------------------------------------------------------------------- /server_side/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonemking/servicenow/HEAD/server_side/.DS_Store -------------------------------------------------------------------------------- /update_sets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonemking/servicenow/HEAD/update_sets/.DS_Store -------------------------------------------------------------------------------- /webservices/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonemking/servicenow/HEAD/webservices/.DS_Store -------------------------------------------------------------------------------- /images/excelsimulator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonemking/servicenow/HEAD/images/excelsimulator.png -------------------------------------------------------------------------------- /server_side/Background_Scripts/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonemking/servicenow/HEAD/server_side/Background_Scripts/.DS_Store -------------------------------------------------------------------------------- /update_sets/kpi_manager/KPI app fron end.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonemking/servicenow/HEAD/update_sets/kpi_manager/KPI app fron end.png -------------------------------------------------------------------------------- /ui/ui_scripts/monitorStatus_ngApp.js: -------------------------------------------------------------------------------- 1 | angular.module('mcdApp', []); 2 | 3 | angular.module('mcdApp').config(function($httpProvider){ 4 | $httpProvider.defaults.headers.common["X-UserToken"] = window.g_ck; 5 | }); -------------------------------------------------------------------------------- /fix_scripts/nuke.js: -------------------------------------------------------------------------------- 1 | /* Nuke table data */ 2 | 3 | function doit(table){ 4 | var gr = new GlideRecord(table); 5 | //gr.addQuery('u_number', '' ); 6 | gr.query(); 7 | gr.deleteMultiple(); 8 | } 9 | doit(table); 10 | -------------------------------------------------------------------------------- /update_sets/README.md: -------------------------------------------------------------------------------- 1 | # kpimanagement.xml 2 | 3 | Create incidents tracking when Performance Analytics thresholds are breached. Also has a KPI creator for categorizing the incidents based on the type of threshold breached. 4 | -------------------------------------------------------------------------------- /update_sets/kpi_manager/README.md: -------------------------------------------------------------------------------- 1 | # kpimanagement.xml 2 | 3 | Create incidents tracking when Performance Analytics thresholds are breached. Also has a KPI creator for categorizing the incidents based on the type of threshold breached. 4 | -------------------------------------------------------------------------------- /ui/ui_scripts/monitorStatus_ngTemplates.js: -------------------------------------------------------------------------------- 1 | angular.module('mcdApp').service('TemplateService', function() { 2 | 3 | "use strict"; 4 | 5 | this.getTemplate = function(name) { 6 | return 'AJAXJellyRunner.do?template=' + name; 7 | }; 8 | }); -------------------------------------------------------------------------------- /client_side/client_scripts/hideOrderGuideVariables.js: -------------------------------------------------------------------------------- 1 | function onLoad() { 2 | var item = $("current_item"); 3 | var guide = $("sysparm_guide"); 4 | if (item != null && guide != null && item.value == guide.value) 5 | return; 6 | g_form.setDisplay('varset', false); 7 | }​ 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

ServiceNow-Scripts

2 |

Useful Scripts that I have developed or curated to accomplish various tasks.

3 | 4 | 10 | 11 |

Feel free to use for yourself.

12 | -------------------------------------------------------------------------------- /wf_scripts/currentrequestitem.js: -------------------------------------------------------------------------------- 1 | answer = pcHelp(); 2 | function pcHelp(){ 3 | var tsk = new GlideRecord('sc_task'); 4 | var id = current.sys_id; 5 | tsk.addQuery('request_item', id); 6 | tsk.addQuery('u_pc_support_needed', true); 7 | tsk.query(); 8 | while(tsk.next()){ 9 | return 'yes'; 10 | 11 | } 12 | return 'no'; 13 | } -------------------------------------------------------------------------------- /server_side/Business_Rules/getcompanyid.js: -------------------------------------------------------------------------------- 1 | //aking - use scratchpad to get server side information to pass to client side. 2 | 3 | (function executeRule(current, previous /*null when async*/) { 4 | var userObject = gs.getUser(); 5 | g_scratchpad.domain = userObject.getCompanyID(); 6 | gs.log(">>>>> Company ID is " + g_scratchpad.domain); 7 | })(current, previous); -------------------------------------------------------------------------------- /libraries/script_includes/userUtils.js: -------------------------------------------------------------------------------- 1 | var userUtils = Class.create(); 2 | userUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, { 3 | 4 | getInfo: function(value){ 5 | var gr = new GlideRecord('sys_user'); 6 | gr.get(this.getParameter('sysparm_user_info')); 7 | return gr.value; 8 | 9 | 10 | }, 11 | 12 | type: 'userUtils' 13 | }); -------------------------------------------------------------------------------- /client_side/catalog_client_scripts/hideorderguidevar.js: -------------------------------------------------------------------------------- 1 | //author servicenow 2 | //hide variable set within an order guide 3 | function onLoad() { 4 | var item = $("current_item"); 5 | var guide = $("sysparm_guide"); 6 | if (item != null && guide != null && item.value == guide.value) 7 | return; 8 | g_form.setDisplay('varset', false); 9 | }​ 10 | -------------------------------------------------------------------------------- /client_side/client_scripts/idcreator.js: -------------------------------------------------------------------------------- 1 | function onSubmit() { 2 | //Type appropriate comment here, and begin script below 3 | var indi = g_form.getReference('u_indicator'); 4 | var ts = g_form.getReference('u_time_series'); 5 | var br = g_form.getReference('u_breakdown'); 6 | 7 | 8 | var id = indi + " / " + ts + " / " + br; 9 | 10 | g_form.setValue('u_indicator', id); 11 | } -------------------------------------------------------------------------------- /server_side/Background_Scripts/updateScope.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var gr = new GlideRecord("sys_metadata");     4 | gr.addQuery("sys_scope","e317c4034f4ba6007849cb4e0210c74b"); //sys_id of the first scoped app   5 | gr.query();   6 | while(gr.next())   7 | {   8 | gr.sys_scope = "e86d81da0fc23200459e943be1050e39"; //Update with correct scope i.e newly created scoped app  9 | gr.setWorkflow(false);     10 | gr.update();     11 | }   12 | -------------------------------------------------------------------------------- /ui/ui_actions/generateCategorieslist.js: -------------------------------------------------------------------------------- 1 | addCat(); 2 | function addCat(){ 3 | var l = new GlideRecord('u_financial'); 4 | l.initialize(); 5 | l.u_demand = current.sys_id; 6 | var fields = l.getElement('u_cost_category'); 7 | var choices = fields.getChoices(); 8 | 9 | for(var i = 0; i < choices.size(); i++){ 10 | l.u_cost_category = choices.get(i); 11 | l.insert(); 12 | } 13 | 14 | action.setRedirectURL(current); 15 | } -------------------------------------------------------------------------------- /client_side/catalog_client_scripts/loadrequestfor.js: -------------------------------------------------------------------------------- 1 | //author Antone king 2 | //load the current cart user into a reference varaible on the catalog item form 3 | 4 | function onLoad() { 5 | var userid = g_user.userName; 6 | var cart = new GlideRecord('sc_cart'); 7 | cart.addQuery('user.user_name', userid); 8 | cart.query(); 9 | if (cart.next()) { 10 | var reqfor = cart.requested_for; 11 | g_form.setValue('variables.lu_scvs_user', reqfor); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /server_side/Business_Rules/usertableseperation.js: -------------------------------------------------------------------------------- 1 | //uses usefulUtils library - aking 2 | 3 | //condition 4 | gs.getUser().getCompanyID() == new usefulUtils().getFieldId('core_company', 'name', 'LUTRON') 5 | 6 | (function executeRule(current, previous /*null when async*/) { 7 | var idInclude = new usefulUtils(); 8 | var id = idInclude.getFieldId('core_company', 'name', 'LUTRON'); 9 | gs.log(">>> Company ID from BR " + id); 10 | current.addQuery('company', id); 11 | 12 | })(current, previous); -------------------------------------------------------------------------------- /client_side/client_scripts/hideemptyvars.js: -------------------------------------------------------------------------------- 1 | //Name: Hide Empty Variables 2 | //Type: OnLoad 3 | //Table: Task 4 | /Inherited: True 5 | 6 | function onLoad() { 7 | //Hide all empty variables using the scratchpad object passed from 'Hide Empty Variables' business rule 8 | if(g_scratchpad.emptyVars != ''){ 9 | var emptyVars = g_scratchpad.emptyVars.split(','); 10 | for(i = 0; i < emptyVars.length; i++){ 11 | g_form.setDisplay('variables.' + emptyVars[i], false); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /notifications/banner.js: -------------------------------------------------------------------------------- 1 | template.print('

'); -------------------------------------------------------------------------------- /notifications/footer.js: -------------------------------------------------------------------------------- 1 | template.print('

'); -------------------------------------------------------------------------------- /client_side/client_scripts/hideknowledgeicon.js: -------------------------------------------------------------------------------- 1 | //aking - using getcompanyid business rule to pass the id from the server. 2 | 3 | function onLoad() { 4 | //Hide the kb icon for users that are apart of Lutron 5 | var comp = '976a049d6fb8d600040636412e3ee499'; //Check if user is associated with Lutron Company 6 | if(comp == g_scratchpad.domain){ 7 | 8 | //find the knowledge icon by class 9 | 10 | document.getElementsByClassName('btn btn-default icon-book knowledge')[0].style.visibility = 'hidden'; 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /wf_scripts/replaceHtml.js: -------------------------------------------------------------------------------- 1 | //https://community.servicenow.com/thread/211412 2 | // Retrieve the 'Description' HTML from the Catalog Item 3 | var text = current.cat_item.description.getDisplayValue(); 4 | 5 | // Replace all
tags with a CRLF 6 | var regX1 = //ig; 7 | var text2 = text.replace(regX1, String.fromCharCode(13)); 8 | 9 | // Replace all remainging HTML tags with "" 10 | var regX2 = /(<([^>]+)>)/ig; 11 | var finalText = text2.replace(regX2, ""); 12 | 13 | // Set the Catalog Task's 'Description' field to the raw text of the Catalog Items 'Description' field 14 | task.description = finalText; -------------------------------------------------------------------------------- /ui/ui_scripts/monitorStatus_ngModel.js: -------------------------------------------------------------------------------- 1 | angular.module('mcdApp').service('SystemStatModel', function($http){ 2 | "use strict"; 3 | 4 | this.initialize = function() { 5 | this.endpoint = '/api/scafe/v1/mas'; 6 | this.searchValue = ''; 7 | this.data = {records: [], total: 0}; 8 | this.getListData(); 9 | return this; 10 | }; 11 | 12 | this.getListData = function() { 13 | var _this = this; 14 | $http.get(_this.endpoint).then(function(response) { 15 | 16 | _this.data.records = response.data.result.records; 17 | _this.data.total = response.data.result.total; 18 | }); 19 | }; 20 | 21 | 22 | }); -------------------------------------------------------------------------------- /libraries/script_includes/financeUtils.js: -------------------------------------------------------------------------------- 1 | 2 | //aking - ptc include for spreadsheet calculator 3 | var financeUtils = Class.create(); 4 | financeUtils.prototype = { 5 | initialize: function() { 6 | }, 7 | 8 | yearRoll: function(query, year) { 9 | var id = current.sys_id; 10 | var count = 0; 11 | var numberField = year; 12 | var rg = new GlideRecord('u_financial'); 13 | rg.addQuery('u_demand', id); 14 | rg.addEncodedQuery(query); 15 | rg.query(); 16 | while(rg.next()){ 17 | var n = parseFloat(rg.getValue(numberField)); 18 | count += n; 19 | gs.log(">>>> count year1 " + count); 20 | 21 | } 22 | return count; 23 | 24 | }, 25 | 26 | type: 'financeUtils' 27 | }; -------------------------------------------------------------------------------- /server_side/Background_Scripts/findReplace.js: -------------------------------------------------------------------------------- 1 | //author antone king 2 | //Replace 'table name here','query here if needed','field name here' ith your parameters for the findreplace 3 | //find replace anything in your instance 4 | 5 | removeAnom('table', 'encodedquery', 'element field') 6 | function removeAnom(table, query, field){ 7 | var gr = new GlideRecord(table); 8 | gr.addEncodedQuery(query); 9 | gr.query(); 10 | var updateCount = 0; 11 | while(gr.next()){ 12 | gr[field] = gr[field].replace(/ (what do you want to find?/g, "'"); 13 | gr.update(); 14 | updateCount++; 15 | 16 | 17 | } 18 | gs.print('Records updated: ' + updateCount); 19 | 20 | 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /server_side/Business_Rules/updaterequest.js: -------------------------------------------------------------------------------- 1 | (function executeRule(current, previous /*null when async*/) { 2 | 3 | var gr= new GlideRecord("sc_req_item"); 4 | gr.addQuery('request',current.sys_id); 5 | gr.query(); 6 | var varArr=''; 7 | while(gr.next()){ 8 | var set = new GlideappVariablePoolQuestionSet(); 9 | set.setRequestID(gr.sys_id); 10 | set.load(); 11 | var vs = set.getFlatQuestions(); 12 | for (var i=0; i < vs.size(); i++) { 13 | if(vs.get(i).getLabel() != '') { 14 | varArr+=vs.get(i).getLabel() + " - " + vs.get(i).getDisplayValue()+'\n'; 15 | } 16 | } 17 | } 18 | current.description=varArr; 19 | current.short_description = gr.variables.Request_title; 20 | 21 | })(current, previous); -------------------------------------------------------------------------------- /ui/ui_macros/monitorTemplate.js: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 | RFM 2 6 |
7 |
8 |
9 | 10 |
11 | 12 |
13 |
-------------------------------------------------------------------------------- /wf_scripts/emaileventparam1.js: -------------------------------------------------------------------------------- 1 | sendMail(); 2 | function sendMail(){ 3 | var value = ''; 4 | var servTsk = new GlideRecord('sc_task'); 5 | var id = current.sys_id; 6 | var group = 'assignment_group=' + getFieldId('sys_user_group', 'name', 'Windows'); 7 | 8 | servTsk.addQuery('request_item', id); 9 | servTsk.addEncodedQuery(group); 10 | servTsk.addNotNullQuery('u_employee_email_address'); 11 | servTsk.query(); 12 | while(servTsk.next()){ 13 | value = servTsk.u_employee_email_address; 14 | } 15 | return value; 16 | } 17 | function getFieldId(table,field,value) { 18 | var fieldId = new GlideRecord(table); 19 | fieldId.addQuery(field, value); 20 | fieldId.query(); 21 | fieldId.next(); 22 | return fieldId.sys_id; 23 | } -------------------------------------------------------------------------------- /wf_scripts/movevaluefromontasktoanother.js: -------------------------------------------------------------------------------- 1 | 2 | function updatePrinceName(){ 3 | var value = ''; 4 | var servTsk = new GlideRecord('sc_task'); 5 | var id = current.sys_id; 6 | var group = 'assignment_group=' + getFieldId('sys_user_group', 'name', 'Service Desk'); 7 | 8 | servTsk.addQuery('request_item', id); 9 | servTsk.addEncodedQuery(group); 10 | servTsk.addNotNullQuery('u_principal_name'); 11 | servTsk.query(); 12 | while(servTsk.next()){ 13 | value = servTsk.u_principal_name; 14 | } 15 | return value; 16 | } 17 | function getFieldId(table,field,value) { 18 | var fieldId = new GlideRecord(table); 19 | fieldId.addQuery(field, value); 20 | fieldId.query(); 21 | fieldId.next(); 22 | return fieldId.sys_id; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /server_side/Business_Rules/finduserrole.js: -------------------------------------------------------------------------------- 1 | var grp = new GlideRecord('sys_group_has_role'); 2 | grp.addQuery('group.name', 'Philadelphia Tickets Project') ; 3 | grp.addQuery('role.name', '111 Call Center Supervisor'); 4 | grp.query(); 5 | while(grp.next()){ 6 | gs.print(">>>> found " + grp.group.getDisplayValue()); 7 | } 8 | 9 | 10 | var gr = new GlideRecord("syslog"); 11 | gr.addEncodedQuery("sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)^level=0^messageLIKEFile not found"); 12 | gr.query(); 13 | while(gr.next()){ 14 | var index = gr.addEncodedQuery("sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)^level=0^messageLIKEFile not found").indexOF("File not found") == 0; 15 | gs.print(index); 16 | } -------------------------------------------------------------------------------- /server_side/Business_Rules/creatIdentifier.js: -------------------------------------------------------------------------------- 1 | //aking - use in conjunction with kpi script action 2 | 3 | (function executeRule(current, previous /*null when async*/) { 4 | 5 | var indi = current.u_indicator.getDisplayValue(); 6 | var ts = current.u_time_series.getDisplayValue(); 7 | var br = current.u_breakdown.getDisplayValue(); 8 | var ele = current.u_element; 9 | 10 | if (ts =='' && br == '' && ele == ''){ 11 | current.u_identifier = indi; 12 | } 13 | else if (ts == '' && ele == ''){ 14 | current.u_identifier = indi + " / " + br; 15 | } 16 | else if (br == ''){ 17 | current.u_identifier = indi + " / " + ts; 18 | } 19 | 20 | else { 21 | current.u_identifier = indi + " / " + br + " / " + ele + " / " + ts; 22 | 23 | } 24 | 25 | })(current, previous); -------------------------------------------------------------------------------- /server_side/Business_Rules/offboarding.js: -------------------------------------------------------------------------------- 1 | function onBefore(current, previous) { 2 | 3 | //This function will be automatically called when this rule is processed. 4 | 5 | setRequestedForFromVariable(); 6 | 7 | function setRequestedForFromVariable() { 8 | current.requested_for = current.variables.requested_for; 9 | current.u_unencrypted_termination_reason = current.variables.termination_reason; 10 | current.description = current.variables.first_name + ' ' + current.variables.last_name + ' - Termination is ' + current.variables.termination_type + '/' + current.variables.termination_process; 11 | 12 | var catRequest = new GlideRecord('sc_request'); 13 | if (catRequest.get(current.request.sys_id)) { 14 | 15 | catRequest.requested_for = current.variables.requested_for; 16 | catRequest.update(); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /scheduled_jobs/reminder.js: -------------------------------------------------------------------------------- 1 | /* Run job everyday against problem record to send reminder emails to the assigned to every other day for a problem ticket 2 | Only send reminder if reminder count field can be divisble by 2 simulating an every other day window 3 | */ 4 | 5 | (function sendReminder(){ 6 | var gr = new GlideRecord('problem'); 7 | gr.addQuery('active', true); 8 | gr.addNotNullQuery('assigned_to'); 9 | gr.query(); 10 | while(gr.next()){ 11 | gr.u_reminder_count += 1; 12 | 13 | if(gr.u_reminder_count % 2 == 0) { 14 | gs.eventQueue('problem.email_reminder', gr, gr.assigned_to, gr.assigned_to.getDisplayValue()); 15 | gs.log(">>> Sending email reminder to " + gr.assigned_to.getDisplayValue() + " for problem record " + gr.number); 16 | gr.u_reminders_sent += 1; 17 | 18 | } 19 | gr.update(); 20 | } 21 | 22 | })(); -------------------------------------------------------------------------------- /server_side/Business_Rules/Cross-reference.js: -------------------------------------------------------------------------------- 1 | /* Cross reference the user table with another and pull information about a user based on that user */ 2 | 3 | crossRef(); 4 | 5 | function crossRef() { 6 | //populate userid based on agent ID - antone king Feb 2016 7 | var prd = new GlideRecord('table'); 8 | prd.query(); 9 | while (prd.next() ) 10 | { 11 | var user = new GlideRecord('sys_user'); 12 | user.addQuery('u_agent_id', prd.u_agent_id); 13 | user.query(); 14 | 15 | if(user.next()) 16 | { 17 | prd.u_employee = user.user_name; 18 | prd.u_employee_id = user.u_employee_id; 19 | prd.u_status = user.u_status; 20 | prd.u_hire_date = user.u_hire_date; 21 | prd.u_recent_hire_date = user.u_recent_hire_date; 22 | prd.u_termination_date = user.u_term_date; 23 | prd.update(); 24 | 25 | } 26 | 27 | 28 | 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /acl_scripts/statusUpdate.js: -------------------------------------------------------------------------------- 1 | /* 2 | table - problem 3 | type - record 4 | operation - write 5 | 6 | name - problem >>> state 7 | 8 | Once the problem ticket have been assigned only the assigned personnel, 9 | members in the assigned personnels team, and/or members in the Problem Management group 10 | can update the status of the problem. 11 | */ 12 | 13 | 14 | var userObj = gs.getUser(), 15 | answer = false; 16 | 17 | if(userObj.isMemberOf('Problem Management') || userObj.isMemberOf(current.assignment_group) || groupList(current.group_list)){ 18 | answer = true; 19 | } 20 | 21 | // Ability to loop through a group list and check if the user belongs to a group within the list array. 22 | function groupList(grpList){ 23 | var list = grpList.split(','); 24 | 25 | for (var i = 0; i < list.length; i++){ 26 | if (userObj.isMemberOf(list[i])){ 27 | return true; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /ui/ui_macros/breakdownchart.js: -------------------------------------------------------------------------------- 1 | var priorArr = []; 2 | var openInc = []; 3 | var resolved = []; 4 | 5 | 6 | var newIncident = new GlideAggregate('incident'); 7 | var count = new Object(); 8 | newIncident.addQuery('active', 'true'); 9 | newIncident.addAggregate('COUNT'); 10 | newIncident.query(); 11 | count.newInc = 0; 12 | while(newIncident.next()){ 13 | priorArr.push(newIncident.priority + ''); 14 | openInc.push(newIncident.getAggregate('COUNT')); 15 | 16 | //count.newInc = newIncident.getAggregate('COUNT'); 17 | 18 | var resIncident = new GlideAggregate('incident'); 19 | resIncident.addQuery('state', 6); 20 | resIncident.addAggregate('COUNT'); 21 | resIncident.query(); 22 | count.resolvedInc = 0; 23 | while(resIncident.next()){ 24 | resolved.push(resIncident.getAggregate('COUNT')); 25 | //count.resolvedInc = resIncident.getAggregate('COUNT')); 26 | } 27 | } -------------------------------------------------------------------------------- /client_side/catalog_client_scripts/ToDateChecker.js: -------------------------------------------------------------------------------- 1 | function onChange(control, oldValue, newValue, isLoading) { 2 | if (isLoading || newValue == '') { 3 | return; 4 | } 5 | var start_date = g_form.getValue('from'); 6 | if (start_date !=''){ 7 | var greater = compareDates("isGreater"); 8 | if (greater == 'false'){ 9 | alert("To date must be greater than the From date"); 10 | g_form.setValue("to",""); 11 | return; 12 | } 13 | } 14 | 15 | function compareDates(parmName){ 16 | var ajax = new GlideAjax("DateComparison"); 17 | ajax.addParam("sysparm_name",parmName); 18 | if (parmName == 'isGreaterCurrent'){ 19 | ajax.addParam("sysparm_formDate",newValue); 20 | } 21 | if (parmName == 'isGreater'){ 22 | ajax.addParam("sysparm_start",start_date); 23 | ajax.addParam("sysparm_end",newValue); 24 | } 25 | ajax.getXMLWait(); 26 | return ajax.getAnswer(); 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /scheduled_jobs/reports.js: -------------------------------------------------------------------------------- 1 | /* 2 | trigger a scheduled report to only managers of a group 3 | */ 4 | 5 | 6 | var group = new GlideRecord("sys_user_group"); 7 | group.addEncodedQuery("typeLIKE9b5ff4a26ff67900b2ddf59eae3ee492^active=true^u_system_group=false"); 8 | group.query(); 9 | var email_list = ''; 10 | var count = 0; 11 | while (group.next()){ 12 | if (count > 0){ 13 | email_list += ','; 14 | } 15 | email_list +=group.manager.email; 16 | count++; 17 | } 18 | if (email_list!=''){ 19 | var job = new GlideRecord("sysauto_report"); 20 | if (job.get("name","scheduled report job name goes here")){ 21 | job.address_list = email_list; 22 | job.update(); 23 | SncTriggerSynchronizer.executeNow(job); 24 | } 25 | } -------------------------------------------------------------------------------- /server_side/list_control/omitNew.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Only the manager of the assignment group or manager of an assignment group in the group list assigned to the problem task can create related problem tasks 4 | 5 | */ 6 | 7 | 8 | var mgr = current.problem.assignment_group.manager.user_name; 9 | var groupList = current.problem.group_list.getDisplayValue(); 10 | var userName = gs.getUserName(); 11 | var answer; 12 | 13 | 14 | if(userName == mgr || gs.hasRole('admin') || mgrFind()){ 15 | answer = false; 16 | } else { 17 | answer = true; 18 | } 19 | 20 | function mgrFind(){ 21 | var list = groupList.split(','); 22 | for(var i = 0; i < list.length; i++){ 23 | if(grpMatch(list[i].trim()) == userName){ 24 | return true; 25 | } 26 | } 27 | } 28 | 29 | function grpMatch(group){ 30 | var grp = new GlideRecord('sys_user_group'); 31 | grp.addQuery('name', group); 32 | grp.query(); 33 | grp.next(); 34 | return grp.manager.user_name; 35 | } -------------------------------------------------------------------------------- /ui/ui_scripts/monitorStatus_ngCtrl.js: -------------------------------------------------------------------------------- 1 | angular.module('mcdApp').controller('SystemStatCtrl', 2 | ['$scope', 'SystemStatModel', 'TemplateService', function($scope, SystemStatModel, TemplateService){ 3 | 4 | "use strict"; 5 | 6 | $scope.model = SystemStatModel.initialize(); 7 | 8 | 9 | $scope.getTemplate = function(name) { 10 | return TemplateService.getTemplate(name); 11 | }; 12 | 13 | $scope.openStatus = function(sysId) { 14 | var modal = new GlideModalForm('MAS', 'u_major_application_status'); 15 | modal.addParm('sysparm_view', 'MAS'); 16 | modal.setSysID(sysId); 17 | modal.render(); 18 | }; 19 | 20 | 21 | var colorMap = { 22 | style1: "bar", 23 | style2: "bar mid", 24 | style3: "bar down" 25 | 26 | }; 27 | 28 | $scope.ChangeClass = function(score){ 29 | if(score == 2){ 30 | return colorMap.style1; 31 | } 32 | else return colorMap.style3; 33 | }; 34 | 35 | }]); -------------------------------------------------------------------------------- /client_side/catalog_client_scripts/InventoryLookup.js: -------------------------------------------------------------------------------- 1 | function onSubmit() { 2 | 3 | var catalogServices = new GlideAjax("BVloanercatServices"); 4 | catalogServices.addParam("sysparm_name","loanerInventoryClient"); 5 | catalogServices.addParam("sysparm_location",g_form.getValue("physical_office")); 6 | catalogServices.getXMLWait(); 7 | var inventory = catalogServices.getAnswer(); 8 | if (inventory == 0){ 9 | alert("There are currently no Loaner Laptops available, there may be a delay in acquiring this by your Start Date."); 10 | } 11 | var catService = new GlideAjax("BVloanercatServices"); 12 | catService.addParam("sysparm_name","userHasloaner"); 13 | catService.addParam("sysparm_user",g_form.getValue('requested_for')); 14 | catService.getXMLWait(); 15 | var hasLoaner = catService.getAnswer(); 16 | if (hasLoaner == 'true'){ 17 | alert("You have an active Loaner Laptop request that has not been closed."); 18 | return false; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /client_side/Calculated_Fields/calctotals.js: -------------------------------------------------------------------------------- 1 | (function calculatedFieldValue(current) { 2 | 3 | var y1 = parseFloat(current.u_year_1.getCurrencyValue()); 4 | var y2 = parseFloat(current.u_year_2.getCurrencyValue()); 5 | var y3 = parseFloat(current.u_year_3.getCurrencyValue()); 6 | var y4 = parseFloat(current.u_year_4.getCurrencyValue()); 7 | var y5 = parseFloat(current.u_year_5.getCurrencyValue()); 8 | 9 | var total = y1+y2+y3+y4+y5; 10 | 11 | return total; // return the calculated value 12 | 13 | })(current); 14 | 15 | (function calculatedFieldValue(current) { 16 | 17 | var h = parseFloat(current.u_hardware_total.getCurrencyValue()); 18 | var s = parseFloat(current.u_software_total.getCurrencyValue()); 19 | var p = parseFloat(current.u_cloud_services_total.getCurrencyValue()); 20 | var c = parseFloat(current.u_professional_services_total.getCurrencyValue()); 21 | 22 | 23 | var total = h+s+p+c; 24 | 25 | return total; // return the calculated value 26 | 27 | })(current); -------------------------------------------------------------------------------- /server_side/Business_Rules/checklistIncomplete.js: -------------------------------------------------------------------------------- 1 | /* 2 | All checklist items must be complete before task can be closed 3 | 4 | Before - update 5 | */ 6 | 7 | (function executeRule(current, previous /*null when async*/) { 8 | 9 | 10 | 11 | function listIncomplete(){ 12 | var id = current.sys_id; 13 | var list = new GlideRecord('checklist'); 14 | list.addQuery('document', id); 15 | list.query(); 16 | if(list.next()){ 17 | var item = new GlideRecord('checklist_item'); 18 | item.addQuery('checklist.document', id); 19 | item.addQuery('complete', false); 20 | item.query(); 21 | if(item.next()) { 22 | 23 | return true; 24 | 25 | 26 | 27 | } 28 | 29 | 30 | 31 | 32 | } 33 | } 34 | if(current.active.changesTo(false) && listIncomplete() == true){ 35 | current.setAbortAction(true); 36 | gs.addErrorMessage("Please complete all checklist items before closting this task"); 37 | } 38 | 39 | })(current, previous); -------------------------------------------------------------------------------- /server_side/Background_Scripts/findAnywhere.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function findAnywhere(sysid, html) { 4 | if (html !== true && html !== 'true') { html = false; } 5 | var check; 6 | var tableName; 7 | var url = gs.getProperty('glide.servlet.uri'); 8 | var table = new GlideRecord('sys_db_object'); 9 | //Make sure we're not looking at a ts (text search) table. 10 | table.addEncodedQuery('sys_update_nameISNOTEMPTY^nameISNOTEMPTY^nameNOT LIKEts_'); 11 | table.query(); 12 | while (table.next()) { 13 | tableName = table.getValue('name'); 14 | check = new GlideRecord(tableName); 15 | if (check.get(sysid)) { 16 | url += tableName + '.do?sys_id=' + sysid; 17 | if (html) { 18 | var htmlUrl = '' + url + ''; 19 | return url; 20 | } 21 | else { 22 | return url; 23 | } 24 | } 25 | } 26 | } 27 | gs.print(findAnywhere('7a0bcb5a4fe5e600200def6d0210c716',false)); 28 | -------------------------------------------------------------------------------- /server_side/mail_script/itemsummary.js: -------------------------------------------------------------------------------- 1 | template.print("Summary of Requested Item: \n"); 2 | template.print("" + gs.getProperty("glide.servlet.uri") + ": \n"); 3 | var desc = current.sysapproval.short_description; 4 | var number = current.sysapproval.number; 5 | 6 | template.print("\n"); 7 | template.print("Request Item " + number + ":" + desc + " \n"); 8 | for (key in current.sysapproval.variables) { 9 | var v = current.sysapproval.variables[key]; 10 | if(v.getGlideObject().getQuestion().getLabel() != '') { 11 | if(v.getDisplayValue() != 'false'){ 12 | if(v.getDisplayValue() != ''){ 13 | if (v != "" && v != null && typeof(v) != "undefined") { 14 | template.space(4); 15 | template.print('' + v.getGlideObject().getQuestion().getLabel() + ": " + v.getDisplayValue() + " \n"); 16 | } 17 | } 18 | } 19 | } 20 | } 21 | template.print("\n"); 22 | -------------------------------------------------------------------------------- /client_side/catalog_client_scripts/FromDataChecker.js: -------------------------------------------------------------------------------- 1 | function onChange(control, oldValue, newValue, isLoading) { 2 | if (isLoading || newValue == '') { 3 | return; 4 | } 5 | 6 | var end_date = g_form.getValue('to'); 7 | var greater = compareDates("isGreaterCurrent"); 8 | if (greater == 'false'){ 9 | alert("From date must be greater than current date"); 10 | g_form.setValue("from",""); 11 | return; 12 | } 13 | if (end_date !=''){ 14 | greater = compareDates("isGreater"); 15 | if (greater == 'false'){ 16 | alert("To date must be greater than From date"); 17 | g_form.setValue("to",""); 18 | return; 19 | } 20 | } 21 | 22 | function compareDates(parmName){ 23 | var ajax = new GlideAjax("DateComparison"); 24 | ajax.addParam("sysparm_name",parmName); 25 | if (parmName == 'isGreaterCurrent'){ 26 | ajax.addParam("sysparm_formDate",newValue.toString()); 27 | } 28 | if (parmName == 'isGreater'){ 29 | ajax.addParam("sysparm_start",newValue.toString()); 30 | ajax.addParam("sysparm_end",end_date.toString()); 31 | } 32 | ajax.getXMLWait(); 33 | return ajax.getAnswer(); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /client_side/catalog_client_scripts/openehelptext.js: -------------------------------------------------------------------------------- 1 | //aking - open help text on page load. Out of the box the help text is collapsed 2 | 3 | function onLoad() { 4 | //Type appropriate comment here, and begin script below 5 | var myVar = g_form.getControl(''); 6 | var myVarHelp = $('question_help_IO_' + myVar.id.split(':')[1] + '_toggle'); 7 | toggleVariableHelpText(myVarHelp); 8 | 9 | var myVar2 = g_form.getControl(''); 10 | var myVarHelp2 = $('question_help_IO_' + myVar2.id.split(':')[1] + '_toggle'); 11 | toggleVariableHelpText(myVarHelp2); 12 | 13 | var myVar3 = g_form.getControl(''); 14 | var myVarHelp3 = $('question_help_IO_' + myVar3.id.split(':')[1] + '_toggle'); 15 | toggleVariableHelpText(myVarHelp3); 16 | } 17 | 18 | 19 | //Helsinki workaround 20 | 21 | 22 | var myVar = g_form.getControl('caller_id').id; 23 | myVar = myVar.replace(':', '_'); 24 | var wrapper = $('question_help_' + myVar + '_toggle_value'); 25 | var image = $('question_help_' + myVar + '_toggle'); 26 | wrapper.show(); 27 | image.addClassName('icon-vcr-down'); 28 | image.removeClassName('icon-vcr-right'); 29 | _frameChanged(); -------------------------------------------------------------------------------- /libraries/script_includes/po_pdf.js: -------------------------------------------------------------------------------- 1 | var PO_PDF = Class.create(); 2 | PO_PDF.prototype = Object.extendsObject(AbstractAjaxProcessor, { 3 | 4 | generatePDF : function(){ 5 | try{ 6 | var sysId = this.getParameter("sysparm_table_id"); 7 | this.cleanRecord(sysId); 8 | var contentHtml = this.getParameter("sysparm_documentBody"); 9 | var html = ''; 10 | var gr =new GlideRecord("u_draft_document"); 11 | gr.initialize(); 12 | html = " Purchase Order"; 13 | html +=contentHtml; 14 | html+=""; 15 | gr.u_document_html = html; 16 | gr.u_record_id = sysId; 17 | gr.insert(); 18 | try{ 19 | new GeneralPOForm.generate(sysId); 20 | }catch(inside_error){ 21 | gs.log("Error when calling generalPOForm " + inside_error.message); 22 | } 23 | 24 | }catch(ex){ 25 | gs.log("Error on PO_PDF.generatePDF " + ex.message); 26 | } 27 | }, 28 | cleanRecord: function(sysId){ 29 | var gr =new GlideRecord("u_draft_document"); 30 | gr.addQuery("u_record_id",sysId); 31 | gr.query(); 32 | gr.next(); 33 | gr.deleteRecord(); 34 | }, 35 | 36 | type: 'PO_PDF' 37 | }); -------------------------------------------------------------------------------- /notifications/itemapproval.js: -------------------------------------------------------------------------------- 1 | /* 2 | ${mail_script:Company.banner} 3 | 4 | Request Item Number: ${number} is pending your approval. Please review this item and either Approve or Reject the user's request. 5 | 6 | ${mail_script:approval_ritm_info} 7 | 8 | Click here to view your approval: ${URI_REF} 9 | 10 | Thank you, 11 | 12 | IT Department 13 | 14 | ${mail_script:incident_script_2} 15 | ${mail_script:company_footer} 16 | 17 | */ 18 | 19 | var approval_id = ''; 20 | var item = new GlideRecord("sc_req_item"); 21 | if (item.get(current.sysapproval)){ 22 | var catalogItem = 'Requested For: '+ item.request.requested_for.name + '
'; 23 | catalogItem += 'Approval Due Date: '+ current.due_date+ '
'; 24 | catalogItem+='Requested Item: '+ item.cat_item.getDisplayValue() + '
'; 25 | catalogItem += ''+item.description + '
'; 26 | var cat_services = new catalogServices(); 27 | var misc = cat_services.ritmVariableInfo(current.sysapproval); 28 | template.print(catalogItem + "
" + misc); 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /ui/ui_scripts/pdf_template.js: -------------------------------------------------------------------------------- 1 | //aking - generate a pdf from html elemets with the content class. 2 | 3 | 4 | function createPDF() { 5 | var pdf = new jsPDF('p', 'pt', 'letter'); 6 | 7 | source = $j('#content')[0]; 8 | 9 | specialElementHandlers = { 10 | 11 | '#bypassme': function (element, renderer) { 12 | // true = "handled elsewhere, bypass text extraction" 13 | return true; 14 | } 15 | }; 16 | margins = { 17 | top: 80, 18 | bottom: 60, 19 | left: 40, 20 | width: 522 21 | }; 22 | 23 | pdf.fromHTML( 24 | source, // HTML string or DOM elem ref. 25 | margins.left, // x coord 26 | margins.top, { // y coord 27 | 'width': margins.width, // max width of content on PDF 28 | 'elementHandlers': specialElementHandlers 29 | }, 30 | 31 | function (dispose) { 32 | pdf.save('Test.pdf'); 33 | }, margins); 34 | } 35 | 36 | // For test purposes only 37 | function createPDFBasic(){ 38 | var doc = new jsPDF(); 39 | doc.text(20,20, "Hello World!"); 40 | doc.text(20,30, "Second Hello World!"); 41 | doc.addPage(); 42 | doc.text(20,20, "Hello World Page 2"); 43 | doc.save('pdfbook.pdf'); 44 | } 45 | -------------------------------------------------------------------------------- /ui/ui_macros/scorecard.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 30 | 31 |
32 |
33 |
34 | 35 |
36 |
37 |

{2.3}

38 |

Client Avg

39 |
40 |
41 |
42 |
43 |

{5}

44 |

Current Score

45 |
46 |
47 |
48 |
49 |

{3.5}

50 |

Your Avg

51 |
52 | 53 |
54 | 55 |
56 | 57 |
58 |
59 |
60 | 61 |
-------------------------------------------------------------------------------- /webservices/rest_apis/monitorStatus_restAPI.js: -------------------------------------------------------------------------------- 1 | (function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { 2 | 3 | var records = [], 4 | id = new eventUtils(), 5 | gr = new GlideRecord('x_scafe_major_app_event'); 6 | 7 | gr.addEncodedQuery('sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)'); 8 | gr.query(); 9 | while(gr.next()){ 10 | records.push({ 11 | sys_id: gr.getUniqueValue(), 12 | number: gr.getValue('number'), 13 | message: gr.getValue('message'), 14 | application: gr.getDisplayValue('application'), 15 | system_status: gr.getDisplayValue('system_status'), 16 | event: gr.getValue('event'), 17 | alert_type: gr.getValue('alert_type'), 18 | coutry: gr.getValue('country'), 19 | market: gr.getValue('market'), 20 | created: gr.getValue('sys_created_on'), 21 | status: gr.getDisplayValue('status'), 22 | count: gr.getValue('count'), 23 | ticket_status: id.getTicketStatus(gr.getUniqueValue()) 24 | 25 | }); 26 | } 27 | return { 28 | records: records, 29 | total: gr.getRowCount() 30 | }; 31 | 32 | })(request, response); -------------------------------------------------------------------------------- /wf_scripts/findsupportgroup.js: -------------------------------------------------------------------------------- 1 | //this will connect to a script include named catalogServices under script inlcude folder and query set desktop support groups 2 | //to assign tasks based on a users location 3 | 4 | updateTask(); 5 | function updateTask(){ 6 | 7 | task.short_description = 8 | task.description = 9 | 10 | var srv = new catalogServices(); 11 | var location = current.request.requested_for.location; 12 | if (location == ""){ 13 | location = getFieldId("cmn_location","name","Coral Gables, FL"); 14 | } 15 | 16 | task.assignment_group = srv.getSupportGroup(location, "Desktop Support"); 17 | 18 | if (task.assignment_group == ""){ 19 | task.assignment_group = srv.getServiceDesk(); 20 | } 21 | 22 | var request = new GlideRecord('sc_request'); 23 | if (request.get(current.request)){ 24 | if (current.variables.request_origination== 'true' && request.assignment_group != getServiceDesk()) { 25 | request.assignment_group = getServiceDesk(); 26 | }else{ 27 | request.assignment_group = task.assignment_group; 28 | } 29 | request.update(); 30 | } 31 | 32 | function getFieldId(table,field,value) { 33 | var fieldId = new GlideRecord(table); 34 | fieldId.addQuery(field, value); 35 | fieldId.query(); 36 | fieldId.next(); 37 | return fieldId.sys_id; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /libraries/script_includes/usefulUtils.js: -------------------------------------------------------------------------------- 1 | var usefulUtils = Class.create(); 2 | usefulUtils.prototype = { 3 | initialize: function() { 4 | }, 5 | /* aking - get ID of any reference field*/ 6 | 7 | getFieldId: function(table,field,value) { 8 | var fieldId = new GlideRecord(table); 9 | fieldId.addQuery(field, value); 10 | fieldId.query(); 11 | fieldId.next(); 12 | //gs.log(">>>> Comany ID Is: " + field.sys_id); 13 | return fieldId.sys_id; 14 | }, 15 | /* aking - Reject Items at the request level */ 16 | processItemApprovals: function(request,approval_value){ 17 | var item = new GlideRecord("sc_req_item"); 18 | item.addQuery("request",current.sys_id); 19 | item.query(); 20 | while (item.next()){ 21 | var approval = new GlideRecord("sysapproval_approver"); 22 | approval.addQuery("sysapproval",item.sys_id); 23 | approval.addQuery("state","rejected"); 24 | gs.log(">>>> items being canceled " + item.sys_id); 25 | approval.query(); 26 | while (approval.next()){ 27 | approval.state = approval_value; 28 | approval.update(); 29 | } 30 | } 31 | }, 32 | 33 | getUserInfo: function(value){ 34 | var gr = new GlideRecord('sys_user'); 35 | gr.addQuery('sys_id', value); 36 | gr.query(); 37 | gr.next(); 38 | return gr.u_cost_center; 39 | 40 | 41 | }, 42 | 43 | type: 'usefulUtils' 44 | }; -------------------------------------------------------------------------------- /client_side/client_scripts/Highlight_VIP_Caller.js: -------------------------------------------------------------------------------- 1 | function onChange(control, oldValue, newValue, isLoading) { 2 | var callerLabel = $('label.incident.caller_id'); 3 | var callerField = $('sys_display.incident.caller_id'); 4 | if (!callerLabel || !callerField) 5 | return; 6 | 7 | if (!newValue) { 8 | callerLabel.setStyle({backgroundImage: ""}); 9 | callerField.setStyle({color: ""}); 10 | return; 11 | } 12 | g_form.getReference('caller_id', vipCallerCallback); 13 | } 14 | 15 | function vipCallerCallback(caller) { 16 | var callerLabel = $('label.incident.caller_id').down('label'); 17 | var callerField = $('sys_display.incident.caller_id'); 18 | if (!callerLabel || !callerField) 19 | return; 20 | 21 | //check for VIP status 22 | if (caller.vip == 'true') { 23 | g_form.setValue('urgency', '1'); 24 | g_form.setValue('impact', '2'); 25 | g_form.setValue('u_vip','true'); 26 | var bgPosition = "95% 55%"; 27 | if (document.documentElement.getAttribute('data-doctype') == 'true') 28 | bgPosition = "5% 45%"; 29 | 30 | callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' }); 31 | callerField.setStyle({color: "red"}); 32 | } else { 33 | callerLabel.setStyle({backgroundImage: ""}); 34 | callerField.setStyle({color: ""}); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /server_side/inbound_actions/parseTable.js: -------------------------------------------------------------------------------- 1 | /** 2 | * converts array-like object to array 3 | * @param collection the object to be converted 4 | * @return {Array} the converted object 5 | */ 6 | function arrayify(collection) { 7 | return Array.prototype.slice.call(collection); 8 | } 9 | 10 | /** 11 | * generates factory functions to convert table rows to objects, 12 | * based on the titles in the table's 13 | * @param {Array[String]} headings the values of the table's 14 | * @return {Function} a function that takes a table row and spits out an object 15 | */ 16 | function factory(headings) { 17 | return function(row) { 18 | return arrayify(row.cells).reduce(function(prev, curr, i) { 19 | prev[headings[i]] = curr.innerText; 20 | return prev; 21 | }, {}); 22 | } 23 | } 24 | 25 | /** 26 | * given a table, generate an array of objects. 27 | * each object corresponds to a row in the table. 28 | * each object's key/value pairs correspond to a column's heading and the row's value for that column 29 | * 30 | * @param {HTMLTableElement} table the table to convert 31 | * @return {Array[Object]} array of objects representing each row in the table 32 | */ 33 | function parseTable(table) { 34 | var headings = arrayify(table.tHead.rows[0].cells).map(function(heading) { 35 | return heading.innerText; 36 | }); 37 | return arrayify(table.tBodies[0].rows).map(factory(headings)); 38 | } -------------------------------------------------------------------------------- /server_side/Business_Rules/orderCatalogItem.js: -------------------------------------------------------------------------------- 1 | /* example use case of ordering a catalog item from a business rule 2 | 3 | this script orders a catalog item to update a organization id for a user if the cost center gets updated from ldap 4 | 5 | Before - update 6 | 7 | condtion - current.cost_center.changes() 8 | */ 9 | 10 | 11 | 12 | (function executeRule(current, previous /*null when async*/) { 13 | var new_unit = current.cost_center.u_company.u_operating_unit, 14 | nBook = new_unit.u_book, 15 | old_unit = previous.cost_center.u_company.u_operating_unit, 16 | oBook = old_unit.u_book; 17 | 18 | if(new_unit != old_unit){ 19 | gs.log(">>>> Inside org id change if statement, new unit is " +new_unit.getDisplayValue() + " and old unit is " +old_unit.getDisplayValue()); 20 | gs.include('Cart'); 21 | var cart = new Cart(); 22 | var item = cart.addItem('d2a4665b37e036800039daa543990edc'); //Org Id Update catalog item 23 | var usr = current.name; 24 | var email = current.email; 25 | var usrid = current.sys_id; 26 | gs.log(">>>> Org Id update for " + usrid); 27 | 28 | cart.setVariable(item, 'orgid_fullname', usr); 29 | cart.setVariable(item, 'orgid_newid', new_unit.getDisplayValue() + ": " + nBook); 30 | cart.setVariable(item, 'orgid_oldid', old_unit.getDisplayValue() + ": " + oBook); 31 | cart.setVariable(item, 'orgid_email', email); 32 | cart.setVariable(item, 'requested_for', usrid); 33 | 34 | cart.placeOrder(); 35 | } 36 | 37 | 38 | })(current, previous); -------------------------------------------------------------------------------- /server_side/Business_Rules/recover.js: -------------------------------------------------------------------------------- 1 | recoverAssets(); 2 | function recoverAssets() { 3 | 4 | var number = 0 , results = [], user = current.name; 5 | var asset = new GlideRecord('alm_asset'); 6 | asset.addQuery('assigned_to.active', false); 7 | asset.query(); 8 | var count = asset.getRowCount(); 9 | 10 | while(asset.next()) { 11 | results.push(number++); 12 | var usr = new GlideRecord('sys_user'); 13 | usr.addEncodedQuery('active=false^sys_updated_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)'); 14 | usr.addQuery('sys_id', asset.assigned_to); 15 | usr.query(); 16 | 17 | if(usr.next() && number > 0) { 18 | 19 | var sc = new GlideRecord('sc_task'); 20 | sc.initialize(); 21 | sc.request_item.request.requested_for = usr.name; 22 | sc.cmdb_ci = asset.ci.getDisplayValue(); 23 | sc.location = usr.location; 24 | sc.short_description = "Asset recovery triggered by LDAP for " + user; 25 | sc.description = asset.display_name + "\r" + "Location: " + usr.location.getDisplayValue(); 26 | sc.insert(); 27 | 28 | } 29 | 30 | } /*if(number > 0){ 31 | 32 | var inc = new GlideRecord('incident'); 33 | inc.initialize(); 34 | inc.short_description = "Asset recovery for " + current.user_name + " has been triggered by ldap"; 35 | inc.insert(); 36 | */ 37 | 38 | /* 39 | var w = new global.Workflow(); 40 | var wfId = w.getWorkflowFromName("Asset Recovery - Self Service"); 41 | var context = w.startFlow(wfId,current,null); 42 | if (context != null) { 43 | current.context = context.sys_id; 44 | } 45 | } */ 46 | 47 | } 48 | -------------------------------------------------------------------------------- /client_side/catalog_client_scripts/CascadeEngine.js: -------------------------------------------------------------------------------- 1 | //author Antone king 2 | //this script will create records based on the input fields filled out in the record producer. Creating multiple records from one 3 | //submit of a record producer. Useful for data entry forms that will insert data for data collection around Performance Analytics. 4 | //the below Catalog Client Script will generate two records upon submittal. 5 | 6 | function onSubmit() { 7 | 8 | // start the glide record and get values for the input fields 9 | var gr = new GlideRecord('table'); 10 | //record producer variable names 11 | var field = ["example1", "example2", "example3", "example4", "example5"]; 12 | //record producer variable names 13 | var field2 = ["t1", "t2", "t3" , "t4", "t5"]; 14 | //record producer variable names 15 | var field3 = ["b1" , "b2", "b3" , "b4" , "b5"]; 16 | //choice list values 17 | var choice = [1 , 2 , 3 , 4, 5]; 18 | 19 | var date = g_form.getValue('u_date'); 20 | var project = g_form.getValue('u_project'); 21 | var employee = g_form.getValue('u_employee'); 22 | 23 | 24 | function glideInit() { 25 | //initialize the insert of values 26 | gr.initialize(); 27 | //gr.u_department = department; 28 | gr.u_project = project; 29 | gr.u_date = date; 30 | gr.u_employee = employee; 31 | 32 | } 33 | 34 | 35 | for (var i = 0; i < field.length; i++) { 36 | if(g_form.getValue(field[i]) != ""){ 37 | glideInit(); 38 | gr. = g_form.getValue(field[i]); 39 | gr. = g_form.getValue(field2[i]); 40 | gr. = g_form.getValue(field3[i]); 41 | gr. = choice[i]; 42 | gr.insert(); 43 | } 44 | 45 | 46 | 47 | } 48 | 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /ui/ui_macros/kpitable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 |

Work Summary

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
Period: Oct 10 - Oct 16P1None P1Total
Backlog Growth %TestTestTest
Change %TestTestTest
Active (Beginning of WeeK)TestTestTest
New (This Week)TestTestTest
Resolved (End of Week)TestTestTest
BacklogTestTestTest
68 |
69 |
-------------------------------------------------------------------------------- /client_side/Calculated_Fields/Financials.js: -------------------------------------------------------------------------------- 1 | (function calculatedFieldValue(current) { 2 | 3 | var y1 = parseFloat(current.u_year_1.getCurrencyValue()); 4 | var y2 = parseFloat(current.u_year_2.getCurrencyValue()); 5 | var y3 = parseFloat(current.u_year_3.getCurrencyValue()); 6 | var y4 = parseFloat(current.u_year_4.getCurrencyValue()); 7 | var y5 = parseFloat(current.u_year_5.getCurrencyValue()); 8 | 9 | var total = y1+y2+y3+y4+y5; 10 | 11 | return total; // return the calculated value 12 | 13 | })(current); 14 | 15 | 16 | (function calculatedFieldValue(current) { 17 | var id = ac6282c1dbc522009c99fbefbf961918; 18 | var gr = new GlideRecord('u_financial'); 19 | gr.addQuery('u_demand', id); 20 | gs.log(">>> Sys ID " + id); 21 | gr.query(); 22 | while(gr.next()){ 23 | if(gr.u_cost_category == "Hardware Purchases"){ 24 | var value1 = parseFloat(current.u_total.getCurrencyValue()); 25 | 26 | } 27 | if(gr.u_cost_category == "Hardware Maintenance"){ 28 | var value2 = parseFloat(current.u_total.getCurrencyValue()); 29 | 30 | } 31 | 32 | } 33 | 34 | return value1 + value2; // return the calculated value 35 | 36 | })(current); 37 | 38 | 39 | var total = 0 40 | var array = new Array(); 41 | array[total] = new Array(); 42 | var rg = new GlideRecord('dmn_demand'); 43 | rg.addQuery('sys_id', 'ac6282c1dbc522009c99fbefbf961918'); 44 | rg.query(); 45 | while(rg.next()){ 46 | var gr = new GlideAggregate('u_financial'); 47 | gr.addQuery('u_demand', rg.sys_id); 48 | gr.addQuery('u_cost_category', 'STARTSWITH', "hardware"); 49 | gr.addAggregate('SUM', 'u_total'); 50 | gs.log(">>> Sys ID " + rg.number); 51 | gr.query(); 52 | while(gr.next()){ 53 | var sum = gr.getAggregate('SUM', 'u_total'); 54 | array[total] = sum; 55 | if( total != 0) 56 | { 57 | var calc = parseFloat(array[total - 1]); 58 | var sum2 = calc + parseFloat(array[total]) 59 | gs.print(">>> SUM " + sum2); 60 | } 61 | total++; 62 | 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /server_side/Business_Rules/populateChecklist.js: -------------------------------------------------------------------------------- 1 | /* 2 | New feature in helsinki allows for checklist creation in support tasks. This script auto populates checklist items in the task. 3 | */ 4 | 5 | /* 6 | Incase you have multiple tasks being created through workflow and only a select few need checklists use a conditon like so (must populate your short_description with a keyword) 7 | 8 | Before - insert 9 | current.description.indexOf('checklist') != -1 10 | 11 | */ 12 | 13 | (function executeRule(current, previous /*null when async*/) { 14 | var taskArr = []; 15 | gs.log(">>> Request item is " + current.request_item.cat_item); 16 | 17 | if(current.request_item.cat_item == 'a9cd8323372c36800039daa543990e61' /*HR Personnel Location Chnage*/){ 18 | taskArr.push("Provide Moving Boxes for relocation","Assign/Move to New Cube/Office", "Building Access Changes based on new user location", "Parking Badge Changes as needed", "FedEx access – verify access or process changes as necessary"); 19 | 20 | } else { 21 | taskArr.push('Move Equipment to New Cube / Office/update ticket with new cubicle/office location','Provide Moving Boxes'); 22 | } 23 | 24 | var table = 'sc_task'; 25 | var listId = ''; 26 | var id = current.sys_id; 27 | var list = new GlideRecord('checklist'); 28 | list.addQuery('document', id + ''); 29 | list.addQuery('table', table); 30 | list.query(); 31 | if(!list.next()){ 32 | 33 | gs.log(">>>> Current task sysid " + typeof current.sys_id + ''); 34 | list.document = current.sys_id + ''; 35 | list.name = 'Property Ops Checklist'; 36 | list.owner = current.opened_by; 37 | list.table = table; 38 | listId = list.insert(); 39 | 40 | for(var i = 0; i < taskArr.length; i ++){ 41 | var item = new GlideRecord('checklist_item'); 42 | 43 | item.checklist = listId; 44 | item.complete = false; 45 | item.name = taskArr[i]; 46 | item.insert(); 47 | } 48 | } 49 | 50 | })(current, previous); -------------------------------------------------------------------------------- /webservices/outbound/rest/outbound.js: -------------------------------------------------------------------------------- 1 | 2 | try { 3 | var r = new RESTMessage('', 'get'); 4 | var response = r.execute(); 5 | 6 | 7 | var jsonString = response.getBody(); 8 | var parser = new JSONParser(); 9 | var parsed = parser.parse(jsonString); 10 | 11 | } catch(e){ 12 | gs.log(e.message); 13 | } 14 | for (i = 0; i < parsed.computer_reports.length; i++) { 15 | var name = parsed.computer_reports[i].Computer_Name; 16 | var make = parsed.computer_reports[i].Make; 17 | var model = parsed.computer_reports[i].Model; 18 | var number_of_processors = parsed.computer_reports[i].Number_of_Processors; 19 | var processor_speed_mhz = parsed.computer_reports[i].Processor_Speed_MHz; 20 | var processor_Type = parsed.computer_reports[i].Processor_Type; 21 | var serial_number = parsed.computer_reports[i].Serial_Number; 22 | var asset_tag = parsed.computer_reports[i].Serial_Number; 23 | var total_ram_mb = parsed.computer_reports[i].Total_RAM_MB; 24 | var operating_system = parsed.computer_reports[i].Operating_System; 25 | var username = parsed.computer_reports[i].Username; 26 | var drive_capacity_mb = parsed.computer_reports[i].Drive_Capacity_MB; 27 | 28 | 29 | 30 | var rec = new GlideRecord(''); 31 | rec.initialize(); 32 | rec.computer_name = name; 33 | rec.make = make; 34 | rec.model = model; 35 | rec.number_of_processors = number_of_processors; 36 | rec.processor_speed_mhz = processor_speed_mhz; 37 | rec.processor_Type = processor_Type; 38 | rec.serial_number = serial_number; 39 | rec.asset_tag = asset_tag; 40 | rec.total_ram_mb = total_ram_mb; 41 | rec.operating_system = operating_system; 42 | rec.username = username; 43 | //rec.warranty_expiration = warranty_expiration; 44 | rec.drive_capacity_mb = drive_capacity_mb; 45 | rec.insert(); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /server_side/script_actions/KPI.js: -------------------------------------------------------------------------------- 1 | //Author - Antone King. Create incidents when PA thresholds are breached 2 | 3 | createIncident(); 4 | function createIncident(){ 5 | var json = new JSON(); 6 | var summary = json.decode(event.parm1); 7 | var scoreDate = summary.scoreDate; 8 | var reachedThresholdCheck = summary.thresholdCheck; 9 | var escape = GlideStringUtil.escapeHTML; 10 | var uuidString = reachedThresholdCheck.uuidString; 11 | var unit = reachedThresholdCheck.unit; 12 | 13 | //split out text from score. This will allow us to compare the score value to a level in order to change the priority of the ticket 14 | var score = reachedThresholdCheck.matchingScore; 15 | var newScore = score.split(" "); 16 | 17 | if (typeof unit == 'undefined'){ 18 | unit = ''; 19 | } 20 | 21 | var condition = reachedThresholdCheck.condition; 22 | var thresholdLevel = reachedThresholdCheck.thresholdLevel; 23 | if (typeof thresholdLevel != 'undefined'){ 24 | condition += ' ' + thresholdLevel; 25 | } 26 | 27 | // Set constants for every generated ticket. These values are consistent with every ticket. If you change these values it will affect every ticket 28 | //that gets inserted. 29 | var kpi = new GlideRecord('u_kpi'); 30 | kpi.addQuery('u_active', true); 31 | kpi.addQuery('u_identifier', uuidString); //This matches up to the breached threshold in the system. 32 | kpi.query(); 33 | 34 | 35 | while(kpi.next()){ 36 | gs.log(">>>> Hits: " + kpi.u_identifier); 37 | var gr = new GlideRecord('incident'); 38 | gr.initialize(); 39 | gr.assigned_to = kpi.u_assigned; 40 | gr.short_description = "Threshold Breached: " + uuidString + " "; 41 | gr.u_kpi_project = kpi.u_project; 42 | gr.assignment_group = kpi.u_assignment_group.sys_id; 43 | gr.priority = kpi.u_priority; 44 | 45 | //This will pull whatever is in the KPI's description field + the details of the breach 46 | gr.description = uuidString + " was " + condition + " On " + scoreDate + "." + " Current score: " + score + "\r\r" + "Please address ASAP." + "\r\r" + kpi.u_description; 47 | 48 | gr.insert(); 49 | gs.log(">>>> Inserted: " + gr.number); 50 | } 51 | 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /libraries/script_includes/chargeBack.js: -------------------------------------------------------------------------------- 1 | var ChargeBackUtils = Class.create(); 2 | ChargeBackUtils.prototype = { 3 | initialize: function() { 4 | 5 | }, 6 | 7 | processData : function(child, apps) { 8 | //var totalProcessed = 0; 9 | var gr2 = new GlideRecord('u_database_charge_calculation'); 10 | gr2.addQuery('u_server.child', child); 11 | gr2.query(); 12 | if(gr2.next()){ 13 | if(gr2.u_app_count != apps){ 14 | gr2.u_app_count = apps; 15 | gr2.update(); 16 | } 17 | else if(gr2.u_db_instance_count != this._getNumDB(child)){ 18 | gr2.u_db_instance_count = this._getNumDB(child); 19 | gr2.update(); 20 | } else{ return;} // skip insert if server already exists or does not need to be updated 21 | 22 | } else { 23 | 24 | if(apps > 0){ 25 | try{ 26 | gr2.initialize(); 27 | gr2.u_server = this._serverNameLookUp(child); 28 | gr2.u_app_count = apps; 29 | gr2.u_db_instance_count = this._getNumDB(child); 30 | //totalProcessed +=1; 31 | gr2.insert(); 32 | } catch(e){ 33 | gs.info("Unable to insert server and perform calculation on chargeback " + server.name + e.lineNumber + ": " + e); 34 | } 35 | } 36 | 37 | else { return;} // skip insert if the number of apps is 0 38 | } 39 | //gs.info("Chargebacks inserted : " + totalProcessed + " servers on " + gs.nowDateTime()); 40 | }, 41 | 42 | _getNumDB : function(child){ 43 | var db_array = this._dbInstanceLookUp(); 44 | var instance_count = 0; 45 | var gr = new GlideRecord('cmdb_rel_ci'); 46 | gr.addQuery('child', child); 47 | gr.query(); 48 | while (gr.next()){ 49 | var length = db_array.length; 50 | for(var i = 0; i < length; i++){ 51 | if(db_array[i] == gr.parent.name){ 52 | instance_count += 1; 53 | continue; 54 | 55 | } 56 | } 57 | } 58 | 59 | return instance_count; 60 | 61 | }, 62 | 63 | _dbInstanceLookUp : function(){ 64 | var db_instance_array = []; 65 | var gr = new GlideRecord('cmdb_ci_db_instance'); 66 | gr.query(); 67 | while (gr.next()){ 68 | db_instance_array.push(gr.name.toString()); 69 | } 70 | return db_instance_array; 71 | 72 | }, 73 | _serverNameLookUp : function(child){ 74 | var gr = new GlideRecord('cmdb_rel_ci'); 75 | gr.addQuery('child', child); 76 | gr.query(); 77 | if(gr.next()){ 78 | return gr.sys_id; 79 | } 80 | }, 81 | 82 | type: 'ChargeBackUtils' 83 | }; -------------------------------------------------------------------------------- /server_side/Business_Rules/hideemptyvar.js: -------------------------------------------------------------------------------- 1 | 2 | //Name: Hide Empty Variables 3 | //Table: Task 4 | //When: display 5 | //Condition: !RP.isPopup() 6 | //Initialize the scratchpad variable 7 | //combine this with hideemptyvar.js client script 8 | g_scratchpad.emptyVars = ''; 9 | 10 | //Check to see if a variable pool exists 11 | var count = 0; 12 | for(vars in current.variable_pool){ 13 | count++; 14 | break; 15 | } 16 | 17 | //If a variable pool exists then collect empty variable names 18 | if(count > 0){ 19 | var emptyVars = []; 20 | var table = current.getTableName(); 21 | //Query for the empty variables for this record 22 | //Catalog item and task variables pull from 'sc_item_option_mtom' table 23 | if(table == 'sc_req_item' || table == 'sc_task'){ 24 | var itemVars = new GlideRecord('sc_item_option_mtom'); 25 | if(table == 'sc_req_item'){ 26 | itemVars.addQuery('request_item', current.sys_id); 27 | } 28 | if(table == 'sc_task'){ 29 | itemVars.addQuery('request_item', current.request_item.sys_id); 30 | } 31 | itemVars.addNullQuery('sc_item_option.value'); 32 | //Exclude Label and Container variables 33 | itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 11); 34 | itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 19); 35 | itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 20); 36 | itemVars.query(); 37 | while(itemVars.next()){ 38 | //Add variable names to the emptyVars array 39 | emptyVars.push(itemVars.sc_item_option.item_option_new.name.toString()); 40 | } 41 | } 42 | else{ 43 | //All other variables pulled from 'question_answer' table 44 | var producerVars = new GlideRecord('question_answer'); 45 | producerVars.addQuery('table_sys_id', current.sys_id); 46 | producerVars.addNullQuery('value'); 47 | //Exclude Label and Container variables 48 | producerVars.addQuery('question.type', '!=', 11); 49 | producerVars.addQuery('question.type', '!=', 19); 50 | producerVars.addQuery('question.type', '!=', 20); 51 | producerVars.query(); 52 | while(producerVars.next()){ 53 | //Add variable names to the emptyVars array 54 | emptyVars.push(producerVars.question.name.toString()); 55 | } 56 | } 57 | 58 | //Store the result in the scratchpad 59 | g_scratchpad.emptyVars = emptyVars.join(); 60 | } 61 | -------------------------------------------------------------------------------- /ui/ui_pages/monitorStatus_dashboard.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | var gr = new GlideRecord('sys_ui_script'); 6 | gr.orderByDesc('sys_updated_on'); 7 | gr.query(); 8 | gr.next(); 9 | gr.getValue('sys_updated_on'); 10 | 11 | 12 | var d = new Date(); 13 | var stringDate = d.toString(); 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 |
28 |
29 | MAS system status 30 |
31 |
32 |

33 | 34 |
35 |
36 |
37 |
38 | All services are online. 39 | 42 | 43 |
44 |
45 |
46 | 47 |
48 |
49 |
50 |
51 |
52 | 53 | 54 |
55 | 56 |
57 |
58 |
59 |
60 |
61 |
62 | 63 |
64 | 65 | -------------------------------------------------------------------------------- /client_side/catalog_client_scripts/cascadevaranswers.js: -------------------------------------------------------------------------------- 1 | function onSubmit() { 2 | //Type appropriate comment here, and begin script below 3 | var req = g_form.getValue('variables.lu_scvs_user'); 4 | 5 | var gr = new GlideRecord('sys_user'); 6 | gr.addQuery('sys_id', req ); 7 | gr.query(); 8 | 9 | while(gr.next()) { 10 | 11 | gr.manager = g_form.getValue('variables.lut_scvs_supervisor'); 12 | gr.location = g_form.getValue('variables.lut_scvs_location'); 13 | gr.u_director = g_form.getValue('variables.lut_scvs_director'); 14 | gr.u_date_required = g_form.getValue('variables.lut_scvs_date_req'); 15 | gr.u_reason_for_purchase = g_form.getValue('variables.lut_scvs_reason_purchase'); 16 | gr.u_location_used = g_form.getValue('variables.lut_scvs_where_used'); 17 | gr.update(); 18 | 19 | } 20 | 21 | } 22 | 23 | function onChange(control, oldValue, newValue, isLoading) { 24 | 25 | if (newValue == '') { 26 | g_form.setValue('variables.lu_scvs_user', ''); 27 | g_form.setValue('variables.lut_scvs_location', ''); 28 | g_form.setValue('variables.lut_scvs_supervisor', ''); 29 | g_form.setValue('variables.lut_scvs_director', ''); 30 | g_form.setValue('variables.lut_scvs_date_req', ''); 31 | g_form.setValue('variables.lut_scvs_reason_purchase', ''); 32 | g_form.setValue('variables.lut_scvs_where_used', ''); 33 | return; 34 | } 35 | 36 | 37 | 38 | 39 | 40 | var req = g_form.getReference('variables.lu_scvs_user', setLocation); 41 | var mgr = g_form.getReference('variables.lu_scvs_user', setManager); 42 | var dir = g_form.getReference('variables.lu_scvs_user', setDirector); 43 | var dt = g_form.getReference('variables.lu_scvs_user', setDate); 44 | var reas = g_form.getReference('variables.lu_scvs_user', setReason); 45 | var where = g_form.getReference('variables.lu_scvs_user', setWhere); 46 | 47 | 48 | 49 | function setLocation(req) { 50 | if (req) 51 | g_form.setValue('variables.lut_scvs_location', req.location); 52 | } 53 | function setManager(mgr) { 54 | if (mgr) 55 | g_form.setValue('variables.lut_scvs_supervisor', mgr.manager); 56 | } 57 | function setDirector(dir){ 58 | if(dir) 59 | g_form.setValue('variables.lut_scvs_director', dir.u_director); 60 | } 61 | function setDate(dt){ 62 | if(dt) 63 | g_form.setValue('variables.lut_scvs_date_req', dt.u_date_required); 64 | } 65 | function setReason(reas){ 66 | if(reas) 67 | g_form.setValue('variables.lut_scvs_reason_purchase', reas.u_reason_for_purchase); 68 | } 69 | function setWhere(where){ 70 | if(where) 71 | g_form.setValue('variables.lut_scvs_where_used', where.u_location_used); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ui/ui_actions/Clone.js: -------------------------------------------------------------------------------- 1 | //condition = (current.state != 6 && current.state != 7) && (gs.hasRole("itil") || gs.hasRole("itil_admin") ) 2 | 3 | var sd = current.short_description; 4 | var desc = current.description; 5 | var cat = current.category; 6 | var scat = current.subcategory; 7 | var wnotes = ""; 8 | getJournalEntries(); 9 | 10 | 11 | var start='incident.do?sys_id=-1&sysparm_query='; 12 | 13 | //edit variables as per requirements 14 | var var1='short_description=' + sd; 15 | var var2='^category=' + cat; 16 | var var3='^subcategory=' + scat; 17 | var var4='^work_notes =' + wnotes; 18 | 19 | //clone incident with the specific variables 20 | var url = gs.getProperty('glide.servlet.uri') + start + var1 + var2 + var3 + var4; 21 | gs.addInfoMessage('Clone of Incident # ' + current.number); 22 | action.setRedirectURL(url); 23 | 24 | //get the entries from journal table 25 | function getJournalEntries() { 26 | var gr = new GlideRecord('sys_journal_field'); 27 | var notesdisplay =""; 28 | gr.addQuery('element_id', current.sys_id); 29 | gr.addQuery('element',"work_notes"); 30 | gr.query(); 31 | while (gr.next()) { 32 | notesdisplay = notesdisplay + '\n' + gr.value + '\n' + ' '; 33 | //gs.addInfoMessage('I am in getJournalEntries ' + gr.element); 34 | } 35 | wnotes=notesdisplay; 36 | return; 37 | } 38 | 39 | 40 | ###################################################################################### 41 | ###################################################################################### 42 | (gs.hasRole("itil") || gs.hasRole("itil_admin") ) 43 | var sd = current.short_description; 44 | var desc = current.description; 45 | var cat = current.category; 46 | var scat = current.subcategory; 47 | var ag = current.assignment_group; 48 | var sla = current.u_sla_type; 49 | var imp = current.impact; 50 | var urg = current.urgency; 51 | var wnotes = ""; 52 | getJournalEntries(); 53 | 54 | 55 | var start='incident.do?sys_id=-1&sysparm_query='; 56 | 57 | //edit variables as per requirements 58 | var var1='short_description=' + sd; 59 | var var2='^category=' + cat; 60 | var var3='^subcategory=' + scat; 61 | var var4='^assignment_group=' + ag; 62 | var var5='^u_sla_type=' + sla; 63 | var var6='^impact=' + imp; 64 | var var7='^urgency=' + urg; 65 | var var8='^work_notes=' + wnotes; 66 | 67 | //clone incident with the specific variables 68 | 69 | if (current.state != 6 && current.state != 7) 70 | var url = gs.getProperty('glide.servlet.uri') + start + var1 + var2 + var3 + var4 + var5 + var6 + var7; 71 | else var url = gs.getProperty('glide.servlet.uri') + start + var1 + var2 + var3 + var4 + var5 + var6 + var7 + var8; 72 | 73 | gs.addInfoMessage('Clone of Incident # ' + current.number); 74 | action.setRedirectURL(url); 75 | 76 | //get the entries from journal table 77 | function getJournalEntries() { 78 | var gr = new GlideRecord('sys_journal_field'); 79 | var notesdisplay =""; 80 | gr.addQuery('element_id', current.sys_id); 81 | gr.addQuery('element',"work_notes"); 82 | gr.query(); 83 | while (gr.next()) { 84 | notesdisplay = notesdisplay + '\n' + gr.value + '\n' + ' '; 85 | //gs.addInfoMessage('I am in getJournalEntries ' + gr.element); 86 | } 87 | wnotes=notesdisplay; 88 | return; 89 | } 90 | 91 | 92 | -------------------------------------------------------------------------------- /notifications/requestlevelApproval.js: -------------------------------------------------------------------------------- 1 | //Author Antone king 2 | //request level approval with the ability to approve or deny individual items in one email message 3 | //bulk approval ability with modified buttons 4 | 5 | var baseURL = gs.getProperty("glide.servlet.uri"); 6 | var itemURL = "nav_to.do?uri=sc_req_item.do?sys_id="; 7 | var req = new GlideRecord("sc_request"); 8 | if (req.get(current.sysapproval)){ 9 | var body = ''; 10 | var itemInfo = ''; 11 | var total = 0; 12 | //antone king update - order of variables 13 | template.print("

Requestor: " + req.requested_for.name+"

"); 14 | template.print("

State: " + req.request_state+"

"); 15 | //body = "

Requestor: " + req.requested_for.name+"

"; 16 | //body += "

State: " + req.request_state+"

"; 17 | body+="

*Click on the buttons below to approve or reject the complete order."+"

"; 18 | //body+="

Description: " + req.description; 19 | var ritm = new GlideRecord("sc_req_item"); 20 | ritm.addQuery("request",req.sys_id); 21 | ritm.query(); 22 | while (ritm.next()){ 23 | total += ritm.quantity * ritm.price; 24 | itemInfo = " - " +ritm.cat_item.name + " - " + "Qty: " + ritm.quantity + " Price(ea): " + "$" + ritm.price; 25 | //body += "

" + ritm.number + ""+ itemInfo +"

"; 26 | //body += "

" + "" + ritm.number + "" + itemInfo + "

"; 27 | //antone king update to add ritm variables 28 | template.print("

Summary of Requested item:" + "
" ); 29 | template.print("

" + ritm.number + ": " + ritm.quantity + " X " + itemInfo + "

"); 30 | template.print("Options:" + "
"); 31 | for( var key in ritm.variables){ 32 | var v = ritm.variables[key]; 33 | if(v.getGlideObject().getQuestion().getLabel() != '' && v.getDisplayValue() != ''){ 34 | //template.space(1); 35 | template.print(" " + v.getGlideObject().getQuestion().getLabel() + " - " + v.getDisplayValue() + "
"); 36 | } 37 | 38 | } 39 | } 40 | total = parseFloat(Math.round(total * 100) / 100).toFixed(2); 41 | body += "Request Total Amount: " + "$" + total + "
"; 42 | body += getImages(req); 43 | template.print(body); 44 | } 45 | function getImages(req){ 46 | var email_address = ''; 47 | var email_prop = new GlideRecord("sys_email_account"); 48 | email_prop.addQuery("name","ServiceNow SMTP"); 49 | email_prop.query(); 50 | while(email_prop.next()){ 51 | email_address = email_prop.user_name; 52 | } 53 | var mail_to = "mailto:"+email_address + "?subject=re:"+ req.number + " - "; 54 | var body = "&body= "+email.watermark; 55 | var approvalURL = mail_to + "approve" + body; 56 | var rejectURL = mail_to + "reject" + body; 57 | 58 | 59 | var approveSrc = baseURL + "/email_approve.gif"; 60 | var rejectSrc = baseURL + "/email_reject.gif"; 61 | var images = ""; 62 | images +="
"; 63 | images += "

Approve "+" || "+" Reject

"; 64 | return images; 65 | } 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /wf_scripts/employeeExists.js: -------------------------------------------------------------------------------- 1 | answer = isNewEmployeeInServiceNow(); 2 | function isNewEmployeeInServiceNow() { 3 | var blFound = "no"; 4 | var userName = getPrincipalName(); 5 | if (userName!=''){ 6 | var newEmployee = new GlideRecord('sys_user'); 7 | newEmployee.addQuery('user_name',userName); 8 | newEmployee.query(); 9 | while (newEmployee.next()) { 10 | var req = new GlideRecord('sc_request'); 11 | if (req.get(current.request)){ 12 | req.requested_for = newEmployee.sys_id; 13 | req.update(); 14 | } 15 | blFound = "yes"; 16 | } 17 | } 18 | return blFound; 19 | 20 | } 21 | 22 | //aking - refactor to check user_name *renamed function to getPrincipalName() from getEmployeeEmail() 23 | function getPrincipalName(){ 24 | var rtnVal = ''; 25 | 26 | //aking - update query string to accomodate OR condition for Service Desk 27 | var strQuery = 'active=true'; 28 | strQuery = strQuery + '^assignment_group='+getFieldId('sys_user_group','name','Windows'); 29 | strQuery = strQuery + '^ORassignment_group='+getFieldId('sys_user_group','name','Service Desk'); 30 | //============================================================================================== 31 | 32 | var scTask= new GlideRecord('sc_task'); 33 | scTask.addQuery('request_item',current.sys_id); 34 | scTask.addEncodedQuery(strQuery); //aking - Grab new query string 35 | scTask.addNotNullQuery('u_principal_name'); //aking - find all tasks with principal name supplied 36 | scTask.query(); 37 | while (scTask.next()) { 38 | //workflow.scratchpad.u_employee_email_address= createNewAccountTask.u_employee_email_address; 39 | rtnVal= scTask.u_principal_name; 40 | 41 | } 42 | return rtnVal; 43 | 44 | } 45 | function getFieldId(table,field,value) { 46 | var fieldId = new GlideRecord(table); 47 | fieldId.addQuery(field, value); 48 | fieldId.query(); 49 | fieldId.next(); 50 | return fieldId.sys_id; 51 | } 52 | 53 | //orignial script below 54 | 55 | /* 56 | answer = isNewEmployeeInServiceNow(); 57 | function isNewEmployeeInServiceNow() { 58 | var blFound = "no"; 59 | var employeeEmail = getEmployeeEmail(); 60 | if (employeeEmail!=''){ 61 | var newEmployee = new GlideRecord('sys_user'); 62 | newEmployee.addQuery('email',employeeEmail); 63 | newEmployee.query(); 64 | while (newEmployee.next()) { 65 | var req = new GlideRecord('sc_request'); 66 | if (req.get(current.request)){ 67 | req.requested_for = newEmployee.sys_id; 68 | req.update(); 69 | } 70 | blFound = "yes"; 71 | } 72 | } 73 | return blFound; 74 | 75 | } 76 | function getEmployeeEmail(){ 77 | var rtnVal = ''; 78 | var scTask= new GlideRecord('sc_task'); 79 | scTask.addQuery('request_item',current.sys_id); 80 | scTask.addEncodedQuery('assignment_group='+getFieldId('sys_user_group','name','Windows')); 81 | scTask.addEncodedQuery('u_employee_email_addressISNOTEMPTY'); 82 | scTask.query(); 83 | while (scTask.next()) { 84 | //workflow.scratchpad.u_employee_email_address= createNewAccountTask.u_employee_email_address; 85 | rtnVal= scTask.u_employee_email_address; 86 | 87 | } 88 | return rtnVal; 89 | 90 | } 91 | function getFieldId(table,field,value) { 92 | var fieldId = new GlideRecord(table); 93 | fieldId.addQuery(field, value); 94 | fieldId.query(); 95 | fieldId.next(); 96 | return fieldId.sys_id; 97 | } 98 | 99 | */ -------------------------------------------------------------------------------- /ui/ui_pages/highchart.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 92 | 93 |
94 |
95 | 96 |
97 |
${newIncidents}
98 |
${incidentsJson}
99 | 100 | 101 |
-------------------------------------------------------------------------------- /libraries/script_includes/FeedbackUtils.js: -------------------------------------------------------------------------------- 1 | //Report on articles a user has not rated. Tied to Crowd voting application - aking 2 | 3 | var FeedbackUtils = Class.create(); 4 | FeedbackUtils.prototype = { 5 | initialize: function() { 6 | 7 | 8 | }, 9 | 10 | processData : function(user_id){ 11 | var hasRated = this._hasRated(); 12 | var arr = []; 13 | var kb = new GlideRecord('kb_knowledge'); 14 | kb.query(); 15 | while(kb.next()){ 16 | arr.push(kb.sys_id.toString()); 17 | } 18 | var gr = new GlideRecord('u_unrated_articles_x'); 19 | gr.initialize(); 20 | var usr = new GlideRecord('sys_user'); 21 | //usr.addEncodeQuery('active=true^nameSTARTSWITHa'); 22 | //usr.addQuery('sys_id','6816f79cc0a8016401c5a33be04be441'); //admin testing 23 | usr.addQuery('sys_id','IN', hasRated.join(',')); 24 | usr.query(); 25 | while(usr.next()){ 26 | for (var i = 0; i < arr.length; i++){ 27 | if(this._kbFeedback(arr[i], usr.sys_id)){ 28 | this._updateUnrated(); 29 | } 30 | else if(this._checkUnrated(arr[i], usr.sys_id)) { 31 | } 32 | else { 33 | //gs.log('no match article must not have been rated by this person'); 34 | gr.u_user = usr.sys_id; 35 | gr.u_unrated = 'true'; 36 | gr.u_article = arr[i]; 37 | gr.insert(); 38 | } 39 | } 40 | 41 | } 42 | }, 43 | 44 | _checkUnrated : function(article, user){ 45 | var value = false; 46 | var gr = new GlideRecord('u_unrated_articles_x'); 47 | gr.query(); 48 | while(gr.next()){ 49 | if(article == gr.u_article && gr.u_user == user){ 50 | value = true; 51 | } 52 | } 53 | return value; 54 | }, 55 | 56 | _updateUnrated: function(article, user){ 57 | var unrated = new GlideRecord('u_unrated_articles_x'); 58 | unrated.query(); 59 | while(unrated.next()){ 60 | if(this._kbFeedback(unrated.u_article, unrated.u_user)){ 61 | gs.log('DELETE ' + unrated.u_article.number); 62 | unrated.deleteRecord(); 63 | } 64 | } 65 | }, 66 | 67 | _kbFeedback : function(article, user){ 68 | var obj = this._userFeed(); 69 | var data; 70 | var value = false; 71 | for (var i = 0; i < obj.length; i++){ 72 | data = obj[i]; 73 | if(data.user == user && article == data.article){ 74 | value = true; 75 | } 76 | } 77 | return value; 78 | 79 | }, 80 | 81 | _userFeed : function(){ 82 | var arr = []; 83 | var articles = []; 84 | var gr = new GlideRecord('sys_user'); 85 | gr.addActiveQuery(); 86 | gr.query(); 87 | while(gr.next()){ 88 | arr.push(gr.sys_id.toString()); 89 | } 90 | var feedback = new GlideRecord('kb_feedback'); 91 | feedback.addQuery('user', 'IN', arr.join(',')); 92 | feedback.query(); 93 | while(feedback.next()){ 94 | var articleObj = {}; 95 | if(feedback.article.short_description != ''){ 96 | articleObj.article = feedback.article.toString(); 97 | articleObj.user = feedback.user.toString(); 98 | articles.push(articleObj); 99 | } 100 | } 101 | return articles; 102 | }, 103 | 104 | _hasRated : function(){ 105 | var arr =[]; 106 | var arrayUtil = new ArrayUtil(); 107 | var feedback = new GlideRecord('kb_feedback'); 108 | feedback.query(); 109 | while(feedback.next()){ 110 | arr.push(feedback.user.toString()); 111 | } 112 | return arrayUtil.unique(arr); 113 | }, 114 | 115 | 116 | type: 'KbUtils' 117 | }; 118 | -------------------------------------------------------------------------------- /server_side/mail_script/request_approval.js: -------------------------------------------------------------------------------- 1 | //Author Antone king 2 | //request level approval with the ability to approve or deny individual items in one email message 3 | //bulk approval ability with modified buttons 4 | 5 | var baseURL = gs.getProperty("glide.servlet.uri"); 6 | var itemURL = "nav_to.do?uri=sc_req_item.do?sys_id="; 7 | var req = new GlideRecord("sc_request"); 8 | 9 | if (req.get(current.sysapproval)){ 10 | var body = ''; 11 | var itemInfo = ''; 12 | var total = 0; 13 | //antone king update - order of variables 14 | template.print("

Requestor: " + req.requested_for.name+"

"); 15 | template.print("

State: " + req.request_state+"

"); 16 | //body = "

Requestor: " + req.requested_for.name+"

"; 17 | //body += "

State: " + req.request_state+"

"; 18 | body+="

*Click on the buttons below to approve or reject the complete order."+"

"; 19 | //body+="

Description: " + req.description; 20 | var ritm = new GlideRecord("sc_req_item"); 21 | ritm.addQuery("request",req.sys_id); 22 | ritm.query(); 23 | template.print(getImages(req)); 24 | while (ritm.next()){ 25 | total += ritm.quantity * ritm.price; 26 | itemInfo = " - " +ritm.cat_item.name + " - " + "Qty: " + ritm.quantity + " Price(ea): " + "$" + ritm.price; 27 | //body += "

" + ritm.number + ""+ itemInfo +"

"; 28 | //body += "

" + "" + ritm.number + "" + itemInfo + "

"; 29 | //antone king update to add ritm variables 30 | template.print("

Summary of Requested item:" + "
" ); 31 | template.print("

" + ritm.number + ": " + ritm.quantity + " X " + itemInfo + "

"); 32 | template.print("Options:" + "
"); 33 | for( var key in ritm.variables){ 34 | var v = ritm.variables[key]; 35 | if(v.getGlideObject().getQuestion().getLabel() != '' && v.getDisplayValue() != ''){ 36 | //template.space(1); 37 | template.print(" " + v.getGlideObject().getQuestion().getLabel() + " - " + v.getDisplayValue() + "
"); 38 | } 39 | 40 | } 41 | } 42 | total = parseFloat(Math.round(total * 100) / 100).toFixed(2); 43 | body += getImages(req); 44 | body += "Request Total Amount: " + "$" + total + "
"; 45 | template.print(body); 46 | } 47 | function getImages(req){ 48 | var email_address = ''; 49 | var email_prop = new GlideRecord("sys_email_account"); 50 | email_prop.addQuery("name","ServiceNow SMTP"); 51 | email_prop.query(); 52 | while(email_prop.next()){ 53 | email_address = email_prop.user_name; 54 | } 55 | var mail_to = "mailto:"+email_address + "?subject=re:"+ req.number + " - "; 56 | var body = "&body= "+email.watermark; 57 | var approvalURL = mail_to + "approve" + body; 58 | var rejectURL = mail_to + "reject" + body; 59 | 60 | 61 | //var approveSrc = baseURL + "/email_approve.gif"; 62 | //var rejectSrc = baseURL + "/email_reject.gif"; 63 | 64 | var approveSrc = baseURL; 65 | var rejectSrc = baseURL; 66 | 67 | /*var images = ""; 68 | images +="
"; 69 | images += "

Approve "+" || "+" Reject

";*/ 70 | 71 | var images = "

Approve "+" || "+" Reject

"; 72 | return images; 73 | } 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /libraries/script_includes/loanerCatServices.js: -------------------------------------------------------------------------------- 1 | //author John Chooi 2 | //functions for a loaner request item and logic for removing that item from stock and updating inventory levels 3 | 4 | var BVLoanercatServices = Class.create(); 5 | BVLoanercatServices.prototype = Object.extendsObject(AbstractAjaxProcessor, { 6 | loanerInventoryClient: function(table){ 7 | var location = this.getParameter("sysparm_location"); 8 | var inventory = this.loanerInventory(table,location); 9 | return inventory; 10 | }, 11 | loanerInventory: function(table,location){ 12 | var inventory = 0; 13 | var itemCount = new GlideAggregate(table); 14 | itemCount.addQuery("u_location",location); 15 | itemCount.addEncodedQuery("u_request_itemISEMPTY"); 16 | itemCount.addAggregate("COUNT"); 17 | itemCount.query(); 18 | while (itemCount.next()){ 19 | inventory = itemCount.getAggregate("COUNT"); 20 | } 21 | return inventory; 22 | }, 23 | userHasloaner: function(table){ 24 | var userID = this.getParameter("sysparm_user"); 25 | var loaner_count = 0; 26 | var rtnValue = "false"; 27 | var loaner = new GlideAggregate(table); 28 | loaner.addEncodedQuery("u_request_item.active=true^u_request_item.requested_for="+userID); 29 | loaner.addAggregate("COUNT"); 30 | loaner.query(); 31 | while (loaner.next()){ 32 | loaner_count = loaner.getAggregate("COUNT"); 33 | } 34 | if (loaner_count > 0){ 35 | rtnValue = "true"; 36 | } 37 | return rtnValue; 38 | }, 39 | getloanerNumber: function (table,ritm){ 40 | var loanerID = ""; 41 | var loaner = new GlideAggregate(table); 42 | loaner.addQuery("u_request_item",ritm); 43 | loaner.query(); 44 | while (loaner.next()){ 45 | loanerID = loaner.sys_id; 46 | } 47 | return loanerID; 48 | }, 49 | releaseloaner: function(table,ritm){ 50 | var loaner = new GlideAggregate(table); 51 | loaner.addQuery("u_request_item",ritm); 52 | loaner.query(); 53 | while (loaner.next()){ 54 | loaner.u_request_item = ''; 55 | loaner.update(); 56 | } 57 | }, 58 | getSupportGroup: function(location, type){ 59 | var rec = new GlideRecord('u_location_support_groups'); 60 | var grpSysid = ''; 61 | rec.addQuery('u_location.sys_id',location); 62 | rec.query(); 63 | while (rec.next()){ 64 | if (rec.u_group.type.getDisplayValue() == type){ 65 | grpSysid = rec.u_group.sys_id; 66 | } 67 | } 68 | return grpSysid; 69 | }, 70 | getServiceDesk:function(){ 71 | var sdId; 72 | var group = new GlideRecord("sys_user_group"); 73 | group.addEncodedQuery("name=Service Desk"); 74 | group.query(); 75 | while (group.next()){ 76 | sdId = group.sys_id; 77 | } 78 | return sdId; 79 | }, 80 | getAssignmentGroup: function (location){ 81 | var groupID = ""; 82 | var cmnLocation = new GlideRecord("cmn_location"); 83 | if (cmnLocation.get(location)){ 84 | if (cmnLocation.name == "Coral Gables, FL"){ 85 | groupID = this.getServiceDesk(); 86 | }else{ 87 | groupID = this.getSupportGroup(location,"Desktop Support"); 88 | } 89 | } 90 | if (groupID == ""){ 91 | groupID = this.getServiceDesk(); 92 | } 93 | return groupID; 94 | }, 95 | getLocationloaner: function(table,task_id){ 96 | var loaner_id =""; 97 | var task = new GlideRecord("sc_task"); 98 | if (task.get(task_id)){ 99 | var location = task.request_item.u_physical_office; 100 | var loaner = new GlideRecord(table); 101 | loaner.addQuery("u_location",location); 102 | loaner.addEncodedQuery("u_request_itemISEMPTY"); 103 | loaner.query(); 104 | while (loaner.next()){ 105 | loaner_id += ","+loaner.sys_id; 106 | } 107 | } 108 | return 'sys_idIN'+loaner_id; 109 | }, 110 | type: 'BVLoanercatServices' 111 | }); -------------------------------------------------------------------------------- /libraries/script_includes/BVLoanercatServices.js: -------------------------------------------------------------------------------- 1 | //author John Chooi 2 | //functions for a loaner request item and logic for removing that item from stock and updating inventory levels 3 | 4 | var BVLoanercatServices = Class.create(); 5 | BVLoanercatServices.prototype = Object.extendsObject(AbstractAjaxProcessor, { 6 | loanerInventoryClient: function(table){ 7 | var location = this.getParameter("sysparm_location"); 8 | var inventory = this.loanerInventory(table,location); 9 | return inventory; 10 | }, 11 | loanerInventory: function(table,location){ 12 | var inventory = 0; 13 | var itemCount = new GlideAggregate(table); 14 | itemCount.addQuery("u_location",location); 15 | itemCount.addEncodedQuery("u_request_itemISEMPTY"); 16 | itemCount.addAggregate("COUNT"); 17 | itemCount.query(); 18 | while (itemCount.next()){ 19 | inventory = itemCount.getAggregate("COUNT"); 20 | } 21 | return inventory; 22 | }, 23 | userHasloaner: function(table){ 24 | var userID = this.getParameter("sysparm_user"); 25 | var loaner_count = 0; 26 | var rtnValue = "false"; 27 | var loaner = new GlideAggregate(table); 28 | loaner.addEncodedQuery("u_request_item.active=true^u_request_item.requested_for="+userID); 29 | loaner.addAggregate("COUNT"); 30 | loaner.query(); 31 | while (loaner.next()){ 32 | loaner_count = loaner.getAggregate("COUNT"); 33 | } 34 | if (loaner_count > 0){ 35 | rtnValue = "true"; 36 | } 37 | return rtnValue; 38 | }, 39 | getloanerNumber: function (table,ritm){ 40 | var loanerID = ""; 41 | var loaner = new GlideAggregate(table); 42 | loaner.addQuery("u_request_item",ritm); 43 | loaner.query(); 44 | while (loaner.next()){ 45 | loanerID = loaner.sys_id; 46 | } 47 | return loanerID; 48 | }, 49 | releaseloaner: function(table,ritm){ 50 | var loaner = new GlideAggregate(table); 51 | loaner.addQuery("u_request_item",ritm); 52 | loaner.query(); 53 | while (loaner.next()){ 54 | loaner.u_request_item = ''; 55 | loaner.update(); 56 | } 57 | }, 58 | getSupportGroup: function(location, type){ 59 | var rec = new GlideRecord('u_location_support_groups'); 60 | var grpSysid = ''; 61 | rec.addQuery('u_location.sys_id',location); 62 | rec.query(); 63 | while (rec.next()){ 64 | if (rec.u_group.type.getDisplayValue() == type){ 65 | grpSysid = rec.u_group.sys_id; 66 | } 67 | } 68 | return grpSysid; 69 | }, 70 | getServiceDesk:function(){ 71 | var sdId; 72 | var group = new GlideRecord("sys_user_group"); 73 | group.addEncodedQuery("name=Service Desk"); 74 | group.query(); 75 | while (group.next()){ 76 | sdId = group.sys_id; 77 | } 78 | return sdId; 79 | }, 80 | getAssignmentGroup: function (location){ 81 | var groupID = ""; 82 | var cmnLocation = new GlideRecord("cmn_location"); 83 | if (cmnLocation.get(location)){ 84 | if (cmnLocation.name == "Coral Gables, FL"){ 85 | groupID = this.getServiceDesk(); 86 | }else{ 87 | groupID = this.getSupportGroup(location,"Desktop Support"); 88 | } 89 | } 90 | if (groupID == ""){ 91 | groupID = this.getServiceDesk(); 92 | } 93 | return groupID; 94 | }, 95 | getLocationloaner: function(table,task_id){ 96 | var loaner_id =""; 97 | var task = new GlideRecord("sc_task"); 98 | if (task.get(task_id)){ 99 | var location = task.request_item.u_physical_office; 100 | var loaner = new GlideRecord(table); 101 | loaner.addQuery("u_location",location); 102 | loaner.addEncodedQuery("u_request_itemISEMPTY"); 103 | loaner.query(); 104 | while (loaner.next()){ 105 | loaner_id += ","+loaner.sys_id; 106 | } 107 | } 108 | return 'sys_idIN'+loaner_id; 109 | }, 110 | type: 'BVLoanercatServices' 111 | }); 112 | -------------------------------------------------------------------------------- /server_side/inbound_actions/inserKb.js: -------------------------------------------------------------------------------- 1 | var gdt = new GlideDate(); 2 | gdt.addDays(2); 3 | //current.valid_to = gdt; 4 | var desc = email.subject; 5 | desc = desc.replace("Knowledge:",""); 6 | current.short_description = desc.trim(); 7 | current.workflow_state = "draft"; 8 | current.topic = "General"; 9 | //current.category = ""; 10 | current.roles = "knowledge_admin"; 11 | 12 | 13 | //Find and replace the image tags with the proper source. 14 | //Get the number of attachments so the loop can be exited 15 | //so it will stop no mater what. 16 | var currentCount = 0; 17 | var newBody = email.body_html; 18 | var searchBody = email.body_html.replace(/\n/g, " "); 19 | 20 | 21 | var regex = //ig; 22 | var match; 23 | var match2; 24 | while(match = regex.exec(searchBody)){ 25 | //Add a style float tag next to the align tag. 26 | var alignText = match[0].replace(/align=['"]?left['"]?/gi, 'align="left" style="FLOAT: left"'); 27 | alignText = alignText.replace(/align=['"]?right['"]?/gi, 'align="right" style="FLOAT: right"'); 28 | searchBody = searchBody.replace(match[0], alignText); 29 | var regex2 = /src=("(.)*?"|'(.)*?'|(.)*?\s+$)?/ig; 30 | while(match2 = regex2.exec(alignText)){ 31 | findAndReplaceImage(match2[1].replace(/\s+$/,"").replace(/"+/g,"").replace(/'+/g,"")); 32 | } 33 | currentCount += 1; 34 | if(currentCount >= 100) 35 | break; 36 | } 37 | searchBody = searchBody.replace(/(.*?)<\/o:p>/ig, ""); 38 | currentCount = 0; 39 | var regex2 = //ig; 40 | while(match = regex2.exec(searchBody)){ 41 | searchBody = searchBody.replace(match[0], ""); 42 | currentCount += 1; 43 | if(currentCount >= 100) 44 | break; 45 | } 46 | currentCount = 0; 47 | var regex2 = /(.*?)/ig; 48 | while(match = regex2.exec(searchBody)){ 49 | searchBody = searchBody.replace(match[0], match[1]); 50 | currentCount += 1; 51 | if(currentCount >= 100) 52 | break; 53 | } 54 | 55 | 56 | //gs.log("Create Morning Post: " + searchBody); 57 | 58 | 59 | current.text = searchBody; 60 | 61 | 62 | current.insert(); 63 | 64 | 65 | event.state="stop_processing"; 66 | 67 | 68 | function getEmailSYSID(emailuid) { 69 | var em = new GlideRecord('sys_email'); 70 | em.addQuery('uid', emailuid); 71 | em.query(); 72 | while(em.next()) { 73 | //we execute the return only within a certain time difference between the creation of the attachment and now (in seconds) 74 | var dif = gs.dateDiff(em.sys_created_on, gs.nowNoTZ(), true); 75 | //gs.log("difference: " + dif + "eid: " + em.sys_id + " uid: " + em.uid); //debug 76 | if(dif < 300 && dif > -300){ 77 | //gs.log('passed dif if: ' + em.sys_id + " uid: " + em.uid); //debug 78 | return em.sys_id; 79 | } 80 | } 81 | return ""; 82 | } 83 | 84 | 85 | 86 | function findAndReplaceImage(imageText){ 87 | var img = imageText; 88 | var imgName = img.substring(4, img.search(/@/i)); 89 | var imgCode = "sys_attachment.do?sys_id="; 90 | //Get the sys_id of the attachment 91 | var gr = new GlideRecord("sys_attachment"); 92 | gr.addQuery("file_name", imgName); 93 | gr.addQuery("table_sys_id", getEmailSYSID(email.uid)); 94 | gr.query(); 95 | if (gr.next()) { 96 | imgCode += gr.sys_id; 97 | } 98 | searchBody = searchBody.replace(img, imgCode); 99 | } -------------------------------------------------------------------------------- /server_side/inbound_actions/offBoarding.js: -------------------------------------------------------------------------------- 1 | //Author Antone King 2 | /* example message that is being consumed 3 | 4 | 5 | EmployeeID=1479658774 6 | Full Name=Phillip Jones 7 | Effective Date=09/1/2016 8 | Department=France Office 9 | Job Title=Lead Dev 10 | Located=Delaware 11 | Supervisor Email=jyeakel@example.com 12 | Employee Type=Employee 13 | Supervisor=jyeakel 14 | Call Type=New Hire 15 | 16 | */ 17 | 18 | //condition email.subject.indexOf("BPM") == 0 || email.subject.indexOf("HRIS Employee") == 0 || email.subject.indexOf("Workday Employee") == 0 19 | gs.include('Cart'); 20 | 21 | createRequest(); 22 | function createRequest() { 23 | var tools = new usefulUtils(); 24 | var cart = new Cart(); 25 | 26 | //Update message body 27 | var msg_b = email.body_text; 28 | var cartmsg = "Received from: " + email.origemail + "\n\n" + msg_b; 29 | 30 | //Set values 31 | var call_type = tools.bodyParser(msg_b, "Call Type", "=").split("\n")[0]; 32 | var emp_id = tools.bodyParser(msg_b, "EmployeeID" , "=" ).split("\n")[0]; 33 | //var ad_username = tools.bodyParser(msg_b, "AD Username", "=").split("\n")[0]; 34 | var full_name = tools.bodyParser(msg_b, "Full Name" , "=" ).split("\n")[0]; 35 | var dept = tools.bodyParser(msg_b, "Department" , "=" ).split("\n")[0]; 36 | var job_title = tools.bodyParser(msg_b, "Job Title" , "=" ).split("\n")[0]; 37 | var supervisor = tools.bodyParser(msg_b, "Supervisor" , "=" ).split("\n")[0]; 38 | var loc = tools.bodyParser(msg_b, "Located" , "=" ).split("\n")[0]; 39 | var emp_type = tools.bodyParser(msg_b, "Employee Type" , "=" ).split("\n")[0]; 40 | var super_email = tools.bodyParser(msg_b, "Supervisor Email" , "=" ).replace(/<[^>]*>/gi, " ").split("\n")[0]; 41 | var eff_date = tools.bodyParser(msg_b, "Effective Date" , "=" ).split("\n")[0]; 42 | 43 | var wf; 44 | 45 | if(call_type.toLowerCase() == "new hire") wf = '876531004f23da006a17ef6d0210c78d'; //on-board 46 | else 47 | wf = 'a584d96c2bf0ee003d02f62219da159a'; //off-board 48 | 49 | 50 | 51 | var item = cart.addItem(wf); 52 | 53 | gs.log(">> Call Type Struc - " + call_type + " " + typeof call_type); 54 | gs.log(">> EmployeeID Struc - " + emp_id + " " + typeof emp_id); 55 | //gs.log(">> AD Username Struc - " + ad_username + " " + typeof ad_username); 56 | gs.log(">> Full Name Struc - " + full_name + " " + typeof full_name); 57 | gs.log(">> Department Struc - " + dept + " " + typeof dept); 58 | gs.log(">> Job title Struc - " + job_title + " " + typeof job_title); 59 | gs.log(">> Supervisor Struc - " + supervisor + " " + typeof supervisor); 60 | gs.log(">> Location Struc - " + loc + " " + typeof loc); 61 | gs.log(">> Employee Type Struc - " + emp_type + " " + typeof emp_type); 62 | gs.log(">> Supervisor Email Struc - " + super_email + " " + typeof super_email); 63 | gs.log(">> Effective Date Struc - " + eff_date + " " + typeof eff_date); 64 | 65 | 66 | 67 | //Set supervisor name 68 | var user = new GlideRecord('sys_user'); 69 | user.addQuery('email', super_email); 70 | user.query(); 71 | if(user.next()){ 72 | cart.setVariable(item, 'lut_onboard_super', user.sys_id); 73 | gs.log(">>> Supervisor name from query " + user.sys_id); 74 | } 75 | 76 | 77 | cart.setVariable(item, 'lut_onboard_calltype', call_type); 78 | cart.setVariable(item, 'lut_EmployeeID', emp_id); 79 | cart.setVariable(item, 'lut_FullName', full_name); 80 | cart.setVariable(item, 'lut_Department', dept); 81 | cart.setVariable(item, 'lut_JobTitle', job_title); 82 | cart.setVariable(item, 'lut_located', loc); 83 | cart.setVariable(item, 'lut_EmployeeType', emp_type); 84 | cart.setVariable(item, 'lut_superemail', super_email); 85 | cart.setVariable(item, 'lut_eff_date', eff_date); 86 | cart.setVariable(item, 'lut_ob_description', cartmsg); // On boarding description 87 | cart.setVariable(item, 'lut_off_description', cartmsg);// Off boarding description 88 | 89 | 90 | 91 | cart.placeOrder(); 92 | 93 | 94 | } -------------------------------------------------------------------------------- /wf_scripts/updateItem.js: -------------------------------------------------------------------------------- 1 | updateRecord(); 2 | function updateRecord(){ 3 | var addDate = new GlideDateTime(); 4 | addDate = calcDueDate(); 5 | var reqItem = new GlideRecord('sc_req_item'); 6 | if (reqItem.get(current.sys_id)){ 7 | var shipping = ''; 8 | reqItem.u_agency_name = current.variables.agency_name; 9 | reqItem.u_alias_first_name = current.variables.alias_first_name; 10 | reqItem.u_alias_last_name = current.variables.alias_last_name; 11 | reqItem.u_alias_middle_name = current.variables.alias_middle_name; 12 | reqItem.u_background_check = current.variables.background_check; 13 | reqItem.u_building_access = returnBool(current.variables.building_access); 14 | reqItem.u_cost_center = current.variables.cost_center; 15 | reqItem.u_create_email = returnBool(current.variables.create_email); 16 | reqItem.u_display_name = current.variables.display_name; 17 | reqItem.u_end_date = current.variables.end_date; 18 | reqItem.u_first_name = current.variables.first_name; 19 | reqItem.u_it_applications = returnBool(current.variables.it_applications); 20 | reqItem.u_it_equipment = returnBool(current.variables.it_equipment); 21 | reqItem.u_last_name = current.variables.last_name; 22 | reqItem.u_manager_name = current.variables.manager_name; 23 | reqItem.u_manager_role = returnBool(current.variables.manager_role); 24 | reqItem.u_middle_name = current.variables.middle_name; 25 | reqItem.description = 'Request from Service Catalog'; 26 | reqItem.u_parking_access = returnBool(current.variables.parking_access); 27 | reqItem.u_onboarding=true; 28 | shipping = current.variables.ship_to_address + ', '; 29 | shipping +=current.variables.city + ', '; 30 | shipping +=current.variables.state+ ', '; 31 | shipping += current.variables.zip; 32 | reqItem.u_physical_office = current.variables.physical_office; 33 | reqItem.u_re_hire = returnBool(current.variables.re_hire); 34 | reqItem.u_shipping_address = shipping; 35 | reqItem.u_start_date = current.variables.start_date; 36 | reqItem.u_change_effective_date = current.variables.start_date; 37 | reqItem.u_system_name = current.variables.system_name; 38 | reqItem.u_terminated_amiss = returnBool(current.variables.terminated_amiss); 39 | if (current.variables.title_position =="Other"){ 40 | reqItem.u_title_position = current.variables.other_title; 41 | }else{ 42 | reqItem.u_title_position = current.variables.title_position; 43 | } 44 | reqItem.u_type_of_personnel = getId(current.variables.type_of_personnel); 45 | reqItem.request.requested_for = current.variables.manager_name; 46 | reqItem.assignment_group = getHR(); 47 | reqItem.due_date = addDate; 48 | reqItem.estimated_delivery = addDate; 49 | reqItem.update(); 50 | } 51 | var req = new GlideRecord('sc_request'); 52 | if (req.get(current.request)){ 53 | if (current.variables.employee_name != ''){ 54 | req.requested_for = current.variables.employee_name; 55 | }else{ 56 | req.requested_for = current.variables.manager_name; 57 | } 58 | req.assignment_group = getHR(); 59 | req.description = 'Request from Service Catalog'; 60 | req.short_description = 'New Hire request from Service Catalog'; 61 | req.due_date = addDate; 62 | req.update(); 63 | } 64 | function getId(value){ 65 | var typeID = ''; 66 | var objTbl = new GlideRecord('u_types_of_personnel'); 67 | objTbl.addQuery('u_personnel_type',value); 68 | objTbl.query(); 69 | while (objTbl.next()){ 70 | typeID = objTbl.sys_id; 71 | } 72 | return typeID; 73 | } 74 | function returnBool(strValue){ 75 | var rtnValue = false; 76 | if (strValue == 'Yes'){ 77 | rtnValue = true; 78 | } 79 | return rtnValue; 80 | } 81 | function getHR(){ 82 | var groupId = ''; 83 | var groupTbl = new GlideRecord('sys_user_group'); 84 | groupTbl.addQuery('name','Recruiting'); 85 | groupTbl.query(); 86 | while (groupTbl.next()){ 87 | groupId = groupTbl.sys_id; 88 | } 89 | return groupId; 90 | } 91 | function calcDueDate(){ 92 | var dc = new DurationCalculator(); 93 | dc.setSchedule('79c34d7d6f0f2500b2ddf59eae3ee4b1'); 94 | dc.setStartDateTime(gs.nowDateTime()); 95 | dc.calcDuration(302400);//adding 7 days 96 | return dc.getEndDateTime(); 97 | } 98 | 99 | } -------------------------------------------------------------------------------- /libraries/script_includes/CompanyMatchAlgo.js: -------------------------------------------------------------------------------- 1 | /* 2 | ** Purpose is to compare string input of new companies being entered into service catalog. OnChange the input is 3 | ** analyzed and a match % is returned and if the first 3 letters of a record matches that is also returned to the user. 4 | ** This will alert the user that a normalized company name could already exist. 5 | ** To use just pass a string input to vendorCompare via AJAX. 6 | ** ToDo: Add Company Alias names to main array to be checked. 7 | ** 8 | */ 9 | 10 | 11 | var VendorRequestUtils = Class.create(); 12 | VendorRequestUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, { 13 | 14 | vendorNameCompare : function(){ 15 | var aliasArr = this.vendorAlias(); 16 | var vendorNormal = this.vendorNormal(); 17 | var newName = this.getParameter('sysparm_newName'); 18 | var threshold = '0.60'; // Control threshold of similiarty. The lower the threshold the more matches 19 | var venArr = []; 20 | var ven = new GlideRecord('core_company'); 21 | ven.addQuery('vendor', true); 22 | ven.query(); 23 | while(ven.next()){ 24 | var obj = {}; 25 | var venName = String(ven.name).toLowerCase(); 26 | venName = venName.replace(/corporation/gi, "").replace(/llc/gi, "").replace(/llp/gi, ""); 27 | 28 | var firstThreeChar = this.firstThree(String(newName).toLowerCase().trim(), venName.trim()); 29 | if(firstThreeChar != ""){ 30 | gs.log("First Three Char Match " + firstThreeChar); 31 | obj.match_on_three = venName.trim(); 32 | } 33 | 34 | var howSimiliar = this.howSimiliar(String(newName).toLowerCase().trim(), venName.trim()); 35 | if(howSimiliar > threshold){ 36 | obj.vendor_name = venName; 37 | obj.similarity_score = howSimiliar; 38 | } 39 | venArr.push(obj); 40 | } 41 | var cleanObj = venArr.filter(function(el) { 42 | // keep element if it's not an object, or if it's a non-empty object 43 | return typeof el != "object" || Array.isArray(el) || Object.keys(el).length > 0; 44 | }); 45 | 46 | gs.log("=======> Vendor Name Comparison " + JSON.stringify(cleanObj)); 47 | var json = new JSON(); 48 | var data = json.encode(cleanObj); 49 | return data; 50 | }, 51 | 52 | howSimiliar : function(s1, s2){ 53 | var longer = s1; 54 | var shorter = s2; 55 | if (s1.length < s2.length) { 56 | longer = s2; 57 | shorter = s1; 58 | } 59 | var longerLength = longer.length; 60 | if (longerLength == 0) { 61 | return 1.0; 62 | } 63 | var editDistance = this.editDistance(longer, shorter); 64 | return (longerLength - editDistance) / parseFloat(longerLength); 65 | }, 66 | 67 | editDistance : function(s1, s2){ 68 | s1 = s1.toLowerCase(); 69 | s2 = s2.toLowerCase(); 70 | var costs = new Array(); 71 | for (var i = 0; i <= s1.length; i++) { 72 | var lastValue = i; 73 | for (var j = 0; j <= s2.length; j++) { 74 | if (i == 0) { 75 | costs[j] = j; 76 | } 77 | else { 78 | if (j > 0) { 79 | var newValue = costs[j - 1]; 80 | if (s1.charAt(i - 1) != s2.charAt(j - 1)) 81 | newValue = Math.min(Math.min(newValue, lastValue), 82 | costs[j]) + 1; 83 | costs[j - 1] = lastValue; 84 | lastValue = newValue; 85 | } 86 | } 87 | } 88 | if (i > 0){ 89 | costs[s2.length] = lastValue; 90 | } 91 | } 92 | return costs[s2.length]; 93 | }, 94 | 95 | cleanObj : function(o){ 96 | for (var k in o) { 97 | if (!o[k] || typeof o[k] !== "object") { 98 | continue; // If null or not an object, skip to the next iteration 99 | } 100 | clearEmpties(o[k]); 101 | if (Object.keys(o[k]).length === 0) { 102 | delete o[k]; // The object had no properties, so delete that property 103 | } 104 | } 105 | }, 106 | 107 | vendorAlias : function(){ 108 | var arr = []; 109 | var alias = new GlideRecord('fn_alias_value'); 110 | alias.addEncodedQuery('config=2241c4ab375dd340231863d2b3990eca' /*config = Company Name*/); 111 | alias.query(); 112 | while(alias.next()){ 113 | var venAlias = String(alias.value).toLowerCase(); 114 | arr.push(venAlias + ''); 115 | } 116 | return arr; 117 | }, 118 | 119 | vendorNormal : function(){ 120 | var arr = []; 121 | var ven = new GlideRecord('core_company'); 122 | ven.addEncodedQuery('vendor=true'); 123 | ven.query(); 124 | while(ven.next()){ 125 | var venName = String(ven.name).toLowerCase(); 126 | arr.push(venName + ''); 127 | } 128 | return arr; 129 | }, 130 | 131 | firstThree : function(vendor, value){ 132 | var vendorSlice = vendor.slice(0,3); 133 | var oldSlice = value.slice(0,3); 134 | if(vendorSlice == oldSlice){ 135 | return value; 136 | } else { 137 | return ""; 138 | } 139 | }, 140 | 141 | 142 | type: 'VendorRequestUtils' 143 | }); 144 | -------------------------------------------------------------------------------- /ui/ui_macros/gauge.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | var rightNow = gs.now(); 8 | var gdt = new GlideDateTime(); 9 | var month = gdt.getMonth(); 10 | var whatMonth = ''; 11 | var day = gdt.getDayOfMonth(); 12 | if(month == 1){ 13 | whatMonth = "Jan"; 14 | } else if(month == 2) { 15 | whatMonth = "Feb"; 16 | } 17 | else if(month == 3) { 18 | whatMonth = "Mar"; 19 | } 20 | else if(month == 4) { 21 | whatMonth = "Apr"; 22 | } 23 | else if(month == 5) { 24 | whatMonth = "May"; 25 | } 26 | else if(month == 6) { 27 | whatMonth = "Jun"; 28 | } 29 | else if(month == 7) { 30 | whatMonth = "Jul"; 31 | }else if(month == 8) { 32 | whatMonth = "Aug"; 33 | }else if(month == 9) { 34 | whatMonth = "Sep"; 35 | }else if(month == 10) { 36 | whatMonth = "Oct"; 37 | }else if(month == 11) { 38 | whatMonth = "Nov"; 39 | }else { 40 | whatMonth = "Dec"; 41 | } 42 | /* 43 | Using bubbleChartUtils 44 | */ 45 | function incRaw(){ 46 | var ga = new bubbleChartUtils(); 47 | return ga.incCalcRaw(); 48 | 49 | } 50 | 51 | function incToday(){ 52 | var ga = new bubbleChartUtils(); 53 | return ga.incCalcToday(); 54 | 55 | } 56 | 57 | var incChange = incToday() / incRaw(); 58 | 59 | function incThroughput(){ 60 | var ga = new bubbleChartUtils(); 61 | return ga.incCalcThroughput(); 62 | } 63 | 64 | var riskBacklog = incThroughput() - incRaw(); 65 | 66 | var riskEfficiency = (riskBacklog / incThroughput()) * 100; 67 | /* 68 | End for incident 69 | */ 70 | 71 | 72 | 73 | 145 | 146 | 194 | 195 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | -------------------------------------------------------------------------------- /libraries/script_includes/eventUtils.js: -------------------------------------------------------------------------------- 1 | var eventUtils = Class.create(); 2 | eventUtils.prototype = { 3 | initialize: function() { 4 | }, 5 | 6 | /* 7 | Query for events...Seperate functions incase querys for markets or segments need to be customized more. 8 | */ 9 | 10 | getRecordsBySegment: function(segment, startTime, endTime){ 11 | //var query = 'sys_created_onONLast ' + startTime + ' days@javascript:gs.daysAgoStart(' + startTime + ')'; 12 | //query += '@javascript:gs.daysAgoEnd(' + endTime + ')'; 13 | //query += '^country.x_scafe_major_app_market_segment=' + segment; 14 | var gr = new GlideRecord('x_scafe_major_app_event'); 15 | gr.addQuery('sys_created_on', '>=', gs.hoursAgo(endTime)); 16 | gr.addQuery('sys_created_on' , '<=', gs.hoursAgo(startTime)); 17 | //gr.addEncodedQuery(query); 18 | gr.query(); 19 | return gr; 20 | }, 21 | 22 | getRecordsByMarket: function(market, startTime, endTime){ 23 | //var query = 'sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)^market=' + market; 24 | var gr = new GlideRecord('x_scafe_major_app_event'); 25 | gr.addQuery('sys_created_on', '>=', gs.hoursAgo(endTime)); 26 | gr.addQuery('sys_created_on' , '<=', gs.hoursAgo(startTime)); 27 | //gr.addEncodedQuery(query); 28 | gr.query(); 29 | return gr; 30 | }, 31 | 32 | getRecordsAll: function(startTime, endTime){ 33 | //var query = 'sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)'; 34 | var gr = new GlideRecord('x_scafe_major_app_event'); 35 | gr.addQuery('sys_created_on', '>=', gs.hoursAgo(endTime)); 36 | gr.addQuery('sys_created_on' , '<=', gs.hoursAgo(startTime)); 37 | //gr.addEncodedQuery(query); 38 | gr.query(); 39 | return gr; 40 | 41 | }, 42 | 43 | getEventCount: function(records){ 44 | return records.getRowCount(); 45 | }, 46 | 47 | getFieldId: function(table,field,value){ 48 | var fieldId = new GlideRecord(table); 49 | fieldId.addQuery(field, value); 50 | fieldId.query(); 51 | fieldId.next(); 52 | return fieldId.sys_id; 53 | }, 54 | /* 55 | Detect if an rfm alert was created with the same subject and the incident record is still active. 56 | */ 57 | rfmErrorDetection: function(table, subject){ 58 | var value = false; 59 | var e = new GlideRecord(table); 60 | var query = 'short_description='+subject; 61 | query += '^active=true^state!=6'; 62 | e.addEncodedQuery(query); 63 | e.query(); 64 | if(e.next()){ 65 | value = true; 66 | 67 | } 68 | return value; 69 | 70 | }, 71 | /* 72 | Detect if a ping alert was created in the last hour with the same subject. 73 | */ 74 | pingErrorDetection: function(table, subject){ 75 | var value = false; 76 | var e = new GlideRecord(table); 77 | var query = 'sys_created_onRELATIVEGE@hour@ago@1'; 78 | query += '^active=true^state!=6^short_description='+subject; 79 | e.addEncodedQuery(query); 80 | e.query(); 81 | if(e.next()){ 82 | value = true; 83 | } 84 | return value; 85 | }, 86 | 87 | getTicketStatus: function(eRecords){ 88 | var gr = new GlideRecord('x_scafe_major_app_event'); 89 | gr.query(); 90 | while(gr.next()){ 91 | var ev = new GlideRecord('incident'); 92 | ev.addNotNullQuery('x_scafe_major_app_maem_reference'); 93 | ev.addQuery('x_scafe_major_app_maem_reference', eRecords); 94 | ev.query(); 95 | if(ev.next()){ 96 | return ev.state.getDisplayValue(); 97 | 98 | } 99 | } 100 | 101 | 102 | 103 | }, 104 | /* 105 | Mobile API Response 106 | */ 107 | 108 | populateResponse: function(events){ 109 | var resp={}; 110 | var market = request.pathParams.market_seg; 111 | 112 | function ticketStatus(){ 113 | var inc = new GlideRecord('incident'); 114 | inc.addNotNullQuery('x_scafe_major_app_maem_reference'); 115 | inc.addQuery('x_scafe_major_app_maem_reference', events.sys_id); 116 | inc.query(); 117 | if(inc.next()){ 118 | return {"short_desc":inc.getValue('short_description'), 119 | "state": inc.state.getDisplayValue(), 120 | "desc": inc.getValue('description'), 121 | "number": inc.getValue('number'), 122 | "priority": inc.getValue('priority')}; 123 | } 124 | } 125 | function getSegment(){ 126 | var country = events.getValue('country'); 127 | var seg = new GlideRecord('cmn_location'); 128 | seg.addQuery('sys_id', country); 129 | seg.query(); 130 | if(seg.next()){ 131 | return seg.getValue('x_scafe_major_app_market_segment'); 132 | } 133 | } 134 | while (events.next()) { 135 | var clazz = events.getTableName(); 136 | var sys_id = events.getValue('sys_id'); 137 | 138 | if (!(clazz in resp)) 139 | resp[clazz] = []; 140 | resp[clazz].push({ 141 | number: events.getValue('number'), 142 | short_desc: events.getValue('short_description'), 143 | sys_id: sys_id, 144 | link: gs.getProperty('glide.servlet.uri') + 'api/now/v2/table/' + clazz + '/' + sys_id, 145 | snowui: gs.getProperty('glide.servlet.uri') + clazz + '.do?sys_id=' + sys_id, 146 | message: events.getValue('message'), 147 | application: events.getDisplayValue('application'), 148 | system_status: events.getDisplayValue('system_status'), 149 | event: events.getValue('event'), 150 | alert_type: events.getValue('alert_type'), 151 | country: events.getDisplayValue('country'), 152 | segment: getSegment(), 153 | market: events.getValue('market'), 154 | status: events.getDisplayValue('status'), 155 | count: events.getValue('count'), 156 | ticket_info: ticketStatus(), 157 | created: events.getValue('sys_created_on') 158 | }); 159 | 160 | } 161 | return resp; 162 | 163 | 164 | 165 | 166 | 167 | }, 168 | 169 | 170 | 171 | type: 'eventUtils' 172 | }; -------------------------------------------------------------------------------- /server_side/Business_Rules/Financials.js: -------------------------------------------------------------------------------- 1 | function onAfter(current, previous){ 2 | //This function will be automatically called when this rule is processed. 3 | /* 4 | var pQuery = 'u_cost_category=5^ORu_cost_category=6^ORu_cost_category=7'; 5 | var hQuery = 'u_cost_category=1^ORu_cost_category=2'; 6 | var sQuery = 'u_cost_category=3^ORu_cost_category=4'; 7 | var cQuery = 'u_cost_category=8'; 8 | //aking total queries 9 | var ptQuery = 'u_cost_category=5^ORu_cost_category=6^ORu_cost_category=7'; 10 | var htQuery = 'u_cost_category=1^ORu_cost_category=2'; 11 | var stQuery = 'u_cost_category=3^ORu_cost_category=4'; 12 | var ctQuery= 'u_cost_category=8'; 13 | 14 | current.u_hardware_total = totalCalc(hQuery); 15 | current.u_software_total = totalCalc(sQuery); 16 | current.u_cloud_services_total = totalCalc(cQuery); 17 | gs.log(">>>>> Cloud " + totalCalc(cQuery)); 18 | current.u_professional_services_total = totalCalc(pQuery); 19 | current.update(); 20 | 21 | function totalCalc(query){ 22 | var rg = new GlideRecord('dmn_demand'); 23 | rg.addQuery('sys_id', current.sys_id); 24 | rg.query(); 25 | if(rg.next()){ 26 | var count = 0; 27 | var numberField = 'u_total'; 28 | var gr = new GlideRecord('u_financial'); 29 | gr.addQuery('u_demand', rg.sys_id); 30 | gr.addEncodedQuery(query); 31 | gr.query(); 32 | while(gr.next()){ 33 | var n = parseFloat(rg.getValue(numberField)); 34 | count += n; 35 | 36 | } 37 | } 38 | return count; 39 | 40 | }*/ 41 | 42 | totalRoll(); 43 | function totalRoll(){ 44 | var superQuery = 'u_cost_category=1^ORu_cost_category=2^ORu_cost_category=3^ORu_cost_category=4^ORu_cost_category=8^ORu_cost_category=5^ORu_cost_category=6^ORu_cost_category=7'; 45 | var f = new financeUtils(); 46 | gs.log(">> fianance Utils Total " + f.yearRoll('u_cost_category=9^ORu_cost_category=10^ORu_cost_category=11^ORu_cost_category=12', 'u_year_1')); 47 | var gr = new GlideRecord('u_financial'); 48 | gr.addQuery('u_demand', current.sys_id); 49 | gs.log(" >>>>> sys id " + current.sys_id); 50 | gr.addEncodedQuery('u_cost_category=13'); 51 | gr.query(); 52 | if(gr.next()){ 53 | gr.u_year_1 = f.yearRoll(superQuery, 'u_year_1'); 54 | gr.u_year_2 = f.yearRoll(superQuery, 'u_year_2'); 55 | gr.u_year_3 = f.yearRoll(superQuery, 'u_year_3'); 56 | gr.u_year_4 = f.yearRoll(superQuery, 'u_year_4'); 57 | gr.u_year_5 = f.yearRoll(superQuery, 'u_year_5'); 58 | gr.update(); 59 | } 60 | 61 | 62 | } 63 | 64 | hardRoll(); 65 | function hardRoll(){ 66 | var f = new financeUtils(); 67 | gs.log(">> fianance Utils hardware" + f.yearRoll('u_cost_category=1^ORu_cost_category=2', 'u_year_1')); 68 | var gr = new GlideRecord('u_financial'); 69 | gr.addQuery('u_demand', current.sys_id); 70 | gs.log(" >>>>> sys id " + current.sys_id); 71 | gr.addEncodedQuery('u_cost_category=9'); 72 | gr.query(); 73 | if(gr.next()){ 74 | gr.u_year_1 = f.yearRoll('u_cost_category=1^ORu_cost_category=2', 'u_year_1'); 75 | gr.u_year_2 = f.yearRoll('u_cost_category=1^ORu_cost_category=2', 'u_year_2'); 76 | gr.u_year_3 = f.yearRoll('u_cost_category=1^ORu_cost_category=2', 'u_year_3'); 77 | gr.u_year_4 = f.yearRoll('u_cost_category=1^ORu_cost_category=2', 'u_year_4'); 78 | gr.u_year_5 = f.yearRoll('u_cost_category=1^ORu_cost_category=2', 'u_year_5'); 79 | gr.update(); 80 | } 81 | 82 | } 83 | 84 | softRoll(); 85 | function softRoll(){ 86 | var f = new financeUtils(); 87 | gs.log(">> fianance Utils software" + f.yearRoll('u_cost_category=3^ORu_cost_category=4', 'u_year_1')); 88 | var gr = new GlideRecord('u_financial'); 89 | gr.addQuery('u_demand', current.sys_id); 90 | gs.log(" >>>>> sys id " + current.sys_id); 91 | gr.addEncodedQuery('u_cost_category=10'); 92 | gr.query(); 93 | if(gr.next()){ 94 | gr.u_year_1 = f.yearRoll('u_cost_category=3^ORu_cost_category=4', 'u_year_1'); 95 | gr.u_year_2 = f.yearRoll('u_cost_category=3^ORu_cost_category=4', 'u_year_2'); 96 | gr.u_year_3 = f.yearRoll('u_cost_category=3^ORu_cost_category=4', 'u_year_3'); 97 | gr.u_year_4 = f.yearRoll('u_cost_category=3^ORu_cost_category=4', 'u_year_4'); 98 | gr.u_year_5 = f.yearRoll('u_cost_category=3^ORu_cost_category=4', 'u_year_5'); 99 | gr.update(); 100 | } 101 | 102 | } 103 | cloudRoll(); 104 | function cloudRoll(){ 105 | var f = new financeUtils(); 106 | gs.log(">> fianance Utils cloud " + f.yearRoll('u_cost_category=8', 'u_year_1')); 107 | var gr = new GlideRecord('u_financial'); 108 | gr.addQuery('u_demand', current.sys_id); 109 | gs.log(" >>>>> sys id " + current.sys_id); 110 | gr.addEncodedQuery('u_cost_category=11'); 111 | gr.query(); 112 | if(gr.next()){ 113 | gr.u_year_1 = f.yearRoll('u_cost_category=8', 'u_year_1'); 114 | gr.u_year_2 = f.yearRoll('u_cost_category=8', 'u_year_2'); 115 | gr.u_year_3 = f.yearRoll('u_cost_category=8', 'u_year_3'); 116 | gr.u_year_4 = f.yearRoll('u_cost_category=8', 'u_year_4'); 117 | gr.u_year_5 = f.yearRoll('u_cost_category=8', 'u_year_5'); 118 | gr.update(); 119 | } 120 | 121 | } 122 | profRoll(); 123 | function profRoll(){ 124 | var f = new financeUtils(); 125 | gs.log(">> fianance Utils prof " + f.yearRoll('u_cost_category=5^ORu_cost_category=6^ORu_cost_category=7', 'u_year_1')); 126 | var gr = new GlideRecord('u_financial'); 127 | gr.addQuery('u_demand', current.sys_id); 128 | gs.log(" >>>>> sys id " + current.sys_id); 129 | gr.addEncodedQuery('u_cost_category=12'); 130 | gr.query(); 131 | if(gr.next()){ 132 | gr.u_year_1 = f.yearRoll('u_cost_category=5^ORu_cost_category=6^ORu_cost_category=7', 'u_year_1'); 133 | gr.u_year_2 = f.yearRoll('u_cost_category=5^ORu_cost_category=6^ORu_cost_category=7', 'u_year_2'); 134 | gr.u_year_3 = f.yearRoll('u_cost_category=5^ORu_cost_category=6^ORu_cost_category=7', 'u_year_3'); 135 | gr.u_year_4 = f.yearRoll('u_cost_category=5^ORu_cost_category=6^ORu_cost_category=7', 'u_year_4'); 136 | gr.u_year_5 = f.yearRoll('u_cost_category=5^ORu_cost_category=6^ORu_cost_category=7', 'u_year_5'); 137 | gr.update(); 138 | } 139 | 140 | } 141 | 142 | 143 | 144 | } 145 | -------------------------------------------------------------------------------- /ui/ui_pages/po.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | var instance = gs.getProperty("glide.servlet.uri"); 19 | instance +="/"; 20 | var bayviewLogo = instance + "BayviewLogo.png" 21 | var bvFinancial = instance + "bayview_financial.png" 22 | var signature = instance + "sw_signature.png"; 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
PURCHASE ORDER
32 | 33 | 34 | var item = new GlideRecord("proc_po_item"); 35 | item.addQuery("purchase_order", "${jvar_sysid}"); 36 | item.orderBy("number"); 37 | item.query(); 38 | item; 39 | var po = new GlideRecord("${jvar_table_name}"); 40 | po.get("${jvar_sysid}"); 41 | var po_date = new GlideDateTime(po.po_date); 42 | var po_date_form = po_date.getDate(); 43 | var due_date = new GlideDateTime(po.due_by); 44 | var due_date_form = due_date.getDate(); 45 | var currDate = new GlideDate(); 46 | var total = new GlideAggregate("proc_po_item"); 47 | total.addQuery("purchase_order", "${jvar_sysid}"); 48 | total.addAggregate("SUM","total_cost"); 49 | total.groupBy("purchase_order"); 50 | total.query(); 51 | var subTotal = 0; 52 | while (total.next()){ 53 | subTotal = total.getAggregate("SUM","total_cost"); 54 | } 55 | 56 | var jvar_i = -1; 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
PURCHASE ORDER: $[po.number]PURCHASE ORDER DATE: $[po_date_form]DATE REQUIRED: $[due_date_form]
SHIP TO:
$[po.ship_to.name]
$[po.ship_to.location.street]
$[po.ship_to.location.city], $[po.ship_to.location.state] $[po.ship_to.location.zip]
BILL TO:
$[po.bill_to.name]
$[po.bill_to.street]
$[po.bill_to.city], $[po.bill_to.state] $[po.bill_to.zip]
VENDOR:
$[po.vendor.name]
$[po.vendor.street]
$[po.vendor.city], $[po.vendor.state] $[po.vendor.zip]
TERMS: $[po.terms.getDisplayValue()]SHIPPING: $[po.shipping.getDisplayValue()]REQUESTOR: $[po.requested_by.name]
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 |
ITEM NO.DESCRIPTIONQTYCAT CODEDEPT CODEUNIT COSTTOTAL
90 | 91 | 92 | 93 | 94 | 95 | 96 | var po_obj = new PurchaseOrder(); 97 | var cat_code = po_obj.getModelCatName(item.model.cmdb_model_category); 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 |
$[item.part_number]$[item.model.display_name]$[item.ordered_quantity]$[cat_code]$[item.request_line.request.requested_for.department.id]$[item.cost]$[item.total_cost]
112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 |
120 | Date: $[currDate] 121 | 122 | SUB-TOTAL$[subTotal]
SHIPPING$[po.ship_rate]
TAX$0.00
TOTAL$[po.total_cost]
140 | 141 |
142 |
-------------------------------------------------------------------------------- /libraries/script_includes/ContractSecurityUtils.js: -------------------------------------------------------------------------------- 1 | /* 2 | ** Secure Contract records based on an assigned business units(BUs). Groups are then assoicated to BUs. If user is in a 3 | ** group attached ta a BU and that BU is assigned to a contract give read access. Child BUs will flow up to 4 layers for 4 | ** users in a Global BU. 5 | ** 6 | ** Set read ACL to: 7 | ** var bu = current.u_contract_team; 8 | ** var userId = gs.getUserID(); 9 | ** var csu = new ContractSecurityUtils(userId, bu); 10 | ** answer = csu.canRead(); 11 | */ 12 | 13 | var ContractSecurityUtils = Class.create(); 14 | ContractSecurityUtils.prototype = { 15 | initialize: function(user, bu) { 16 | this.reader = 'contract_requestors'; 17 | this.manager = 'contract_creator'; 18 | this.admin = 'contract_admin'; 19 | this.user = user; 20 | this.bu = bu; 21 | }, 22 | 23 | canRead : function(){ 24 | var role = this.reader; 25 | var groupsInBu = this._groupBuAssociations(this.bu); // store string list of groups connected to the bu 26 | var userInBuGroup = this._hasGroupsExactly(groupsInBu); // return true if user is in a group connected to the BU 27 | gs.log('[READ ACCESS] canRead() userInBuGroup ' + userInBuGroup ); 28 | if(this._hasRoleExactly(role)){ 29 | if(userInBuGroup){ 30 | gs.log('[READ ACCESS] Groups are connected to this BU'); 31 | return true; 32 | } else { 33 | 34 | var parentId = this._hasParent(this.bu); 35 | var groupsInParentBu = this._groupBuAssociations(parentId); 36 | var userInParentBu = this._hasGroupsExactly(groupsInParentBu); 37 | gs.log('[READ ACCESS] canRead() userInParentBu ' + userInParentBu ); 38 | if(userInParentBu){ 39 | gs.log('[READ ACCESS] BU does not have a groups associated but Parent Does'); 40 | return true; 41 | } else { 42 | 43 | var topLvlParentId = this._hasTopLvlParent(this.bu); 44 | var groupsInTopLvlParentBu = this._groupBuAssociations(topLvlParentId); 45 | var userInTopLvlParentBu = this._hasGroupsExactly(groupsInTopLvlParentBu); 46 | gs.log('[READ ACCESS] canRead() topLvlParentId ' + topLvlParentId ); 47 | if(userInTopLvlParentBu){ 48 | gs.log('[READ ACCESS] BU does not have any groups associated but Top Level Parent Does'); 49 | return true; 50 | } 51 | } 52 | } 53 | } 54 | return false; 55 | }, 56 | 57 | canCreate : function(){ 58 | var role = this.manager; 59 | if(this._hasRoleExactly(role) && this.canRead()){ 60 | return true; 61 | } 62 | return false; 63 | }, 64 | 65 | canWrite : function(){ 66 | var role = this.manager; 67 | if(this.canDelete() || this._accessRecurse(role) || this.bu == ''){ 68 | return true; 69 | } 70 | return false; 71 | 72 | }, 73 | 74 | canDelete : function(){ 75 | var role = this.admin; 76 | return this._accessRecurse(role); 77 | }, 78 | 79 | // Is Global BU 80 | isGlobal : function(){ 81 | var grObject = this._buGR(this.bu); 82 | var result = false; 83 | if(grObject.next()){ 84 | if(grObject.getDisplayValue('u_top_level_parent') === '' && grObject.getDisplayValue('u_location') === 'Global'){ 85 | result = true; 86 | } 87 | } 88 | return result; 89 | }, 90 | 91 | // BU has no top level parent 92 | isRegion : function(){ 93 | var result = false; 94 | var grObject = this._buGR(this.bu, false, false); 95 | if(grObject.next()){ 96 | if((grObject.getDisplayValue('u_top_level_parent') === '' && grObject.getDisplayValue('parent') !== '')){ 97 | result = true; 98 | } 99 | } 100 | return result; 101 | }, 102 | 103 | // BU has a parent and top level parent 104 | isSubRegion : function(){ 105 | var result = false; 106 | var grObject = this._buGR(this.bu); 107 | if(grObject.next()){ 108 | if(!this.isRegion(this.bu) && !this.isGlobal(this.bu)){ 109 | result = true; 110 | } 111 | } 112 | return result; 113 | }, 114 | 115 | _accessRecurse : function(role){ 116 | var groupsInBu = this._groupBuAssociations(this.bu); 117 | var userHasGroup = this._userHasGroup(groupsInBu); 118 | if (this._groupHasRole(userHasGroup).indexOf(role) > -1){ 119 | return true; 120 | } else { 121 | var parentId = this._hasParent(this.bu); 122 | var groupsInParentBu = this._groupBuAssociations(parentId); 123 | var userHasGroupParent = this._userHasGroup(groupsInParentBu); 124 | if(this._groupHasRole(userHasGroupParent).indexOf(role) > -1){ 125 | return true; 126 | } else { 127 | var topLvlParentId = this._hasTopLvlParent(this.bu); 128 | var groupsInTopLvlParentBu = this._groupBuAssociations(topLvlParentId); 129 | var userHasGroupTop = this._userHasGroup(groupsInTopLvlParentBu); 130 | if(this._groupHasRole(userHasGroupTop).indexOf(role) > -1){ 131 | return true; 132 | } 133 | } 134 | return false; 135 | } 136 | 137 | }, 138 | 139 | // BU GlidRecord Object 140 | _buGR : function(bu){ 141 | var gr = new GlideRecord('business_unit'); 142 | gr.addQuery('sys_id', bu); 143 | gr.addQuery('u_active', 'true'); 144 | gr.query(); 145 | return gr; 146 | }, 147 | 148 | // Group BU associations 149 | _groupBuAssociations : function(bu){ 150 | var buStr; 151 | var grObject = this._buGR(bu); 152 | if(grObject.next()){ 153 | buStr = grObject.getValue('u_groups') + ''; 154 | } 155 | if(buStr){ 156 | gs.log('[READ ACCESS] BU Association ' + buStr); 157 | return buStr; 158 | } else { 159 | return ''; 160 | } 161 | 162 | 163 | }, 164 | 165 | _hasRoleExactly : function(role){ 166 | var rol = new GlideRecord('sys_user_role'); 167 | rol.addQuery('name', role); 168 | rol.query(); 169 | if (rol.next()) { 170 | var hasRole = new GlideRecord('sys_user_has_role'); 171 | hasRole.addQuery('user', this.user); 172 | hasRole.addQuery('role', rol.sys_id); 173 | hasRole.query(); 174 | if (hasRole.next()) { 175 | return true; 176 | } else { 177 | return false; 178 | } 179 | } 180 | return false; 181 | }, 182 | 183 | _userHasGroup : function(groups){ 184 | gs.log('Groups being passed to _userHasGroup func ' + groups); 185 | var arr; 186 | var hasGroup = new GlideRecord('sys_user_grmember'); 187 | hasGroup.addQuery('user', this.user); 188 | hasGroup.addQuery('group', 'IN', groups); 189 | hasGroup.query(); 190 | if (hasGroup.next()) { 191 | //arr.push(hasGroup.group + ''); 192 | arr = hasGroup.group.toString(); 193 | } 194 | //gs.log('====> '+ this.user + ' User has the following Group ' + arr); 195 | return arr; 196 | 197 | }, 198 | 199 | _hasGroupsExactly : function(groups){ 200 | gs.log('Groups passed to _hasGroupsExactly func ' + groups); 201 | var hasGroup = new GlideRecord('sys_user_grmember'); 202 | hasGroup.addQuery('user', this.user); 203 | hasGroup.addQuery('group', 'IN', groups); 204 | hasGroup.query(); 205 | if (hasGroup.next()) { 206 | gs.log('[READ ACCESS] true'); 207 | return true; 208 | } else { 209 | //gs.log('[READ ACCESS] ' + this.user + ' User does not have any groups associated with a BU'); 210 | return false; 211 | } 212 | 213 | }, 214 | 215 | _groupHasRole : function(groups){ 216 | var roles = []; 217 | var groupRole = new GlideRecord('sys_group_has_role'); 218 | groupRole.addQuery('group', 'IN', groups); 219 | groupRole.query(); 220 | while(groupRole.next()){ 221 | roles.push(groupRole.getDisplayValue('role') + ''); 222 | } 223 | //gs.log('====> ' + groups + ' has roles ' + roles); 224 | return roles; 225 | }, 226 | 227 | _hasParent : function(parentBu){ 228 | gs.log(' BU has a parent and child passed to it was ' + parentBu); 229 | var gr = new GlideRecord('business_unit'); 230 | //var parentGr = gr.addQuery('sys_id', parentBu); 231 | //parentGr.addOrCondition('parent', parentBu); 232 | gr.addQuery('sys_id', parentBu); 233 | gr.query(); 234 | if(gr.next()){ 235 | gs.log('[READ ACCCESS] + _hasParent ' + gr.parent); 236 | return gr.getValue('parent'); 237 | } 238 | }, 239 | _hasTopLvlParent : function(topLvlParentBu){ 240 | gs.log('[READ ACCESS] _hasTopLvlParent func value ' + topLvlParentBu); 241 | var buId; 242 | var groupAssociations; 243 | var layer4 = false; 244 | var gr = new GlideRecord('business_unit'); 245 | //var parentGr = gr.addQuery('sys_id', topLvlParentBu); 246 | //parentGr.addOrCondition('u_top_level_parent', topLvlParentBu); 247 | gr.addQuery('sys_id', topLvlParentBu); 248 | gr.addNotNullQuery('u_top_level_parent'); 249 | gr.query(); 250 | if(gr.next()){ 251 | buId = gr.getValue('u_top_level_parent') + ''; 252 | if(buId){ 253 | groupAssociations = this._groupBuAssociations(buId); 254 | if(groupAssociations == 'null'){ 255 | layer4 = true; 256 | 257 | } 258 | } 259 | } 260 | if(layer4){ 261 | buId = this._hasParent(buId); 262 | //gs.log('[READ ACCESS] 4th layer ' + topLvlParentBu + ' returing parent of top level BU ' + buId); 263 | return buId; 264 | }else { 265 | //gs.log("[READ ACCESS] 3rd Layer " + buId + " groups type " + groupAssociations); 266 | return buId; 267 | } 268 | 269 | }, 270 | 271 | 272 | 273 | type: 'ContractSecurityUtils' 274 | }; 275 | -------------------------------------------------------------------------------- /ui/ui_pages/barchart.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | var times = []; //Dates used in the chart 6 | var changes = [];//Change data 7 | var incidents = [];//Incident data 8 | var changesJson = '['; //Change data to JSON used for chart data. 9 | var incidentsJson = '['; //Incident data to JSON used for chart data. 10 | //Get From and To dates from the URL. 11 | var sFrom = RP.getParameterValue('from')+'' != '' ? RP.getParameterValue('from')+' 00:00:00' : gs.daysAgo(5); 12 | var sTo = RP.getParameterValue('to')+'' != '' ? RP.getParameterValue('to')+' 00:00:00' : gs.daysAgo(0); 13 | //Query the sys_trend table for open changes 14 | var grChanges = new GlideRecord('sys_trend'); 15 | grChanges.addQuery('name', 'Open Change Tickets'); 16 | grChanges.addEncodedQuery("collected>=javascript:gs.dateGenerate('"+sFrom+"')^collected<=javascript:gs.dateGenerate('"+sTo+"')^collectedDATEPART1 am@javascript:gs.datePart('hour', '1','EE')"); 17 | grChanges.orderBy('field_value'); 18 | grChanges.query(); 19 | var act = 0; 20 | while (grChanges.next()) { 21 | changes.push(grChanges.value.toString()); 22 | changesJson += '{"y": '+parseInt(grChanges.value.toString(), 10)+', "name": "'+grChanges.collected+'", "drilldown": "drillChanges"},'; 23 | times.push(grChanges.collected.toString()); 24 | //Get the trend data for incident on the same date. 25 | var grIncs = new GlideRecord('sys_trend'); 26 | grIncs.addQuery('name', 'Open Incident Tickets'); 27 | grIncs.addQuery('collected', grChanges.collected); 28 | grIncs.query(); 29 | while(grIncs.next()){ 30 | incidents.push(grIncs.value.toString()); 31 | incidentsJson += '{"y": '+parseInt(grIncs.value.toString(), 10)+', "name": "'+grChanges.collected+'", "drilldown": "group1"},'; 32 | } 33 | if(grIncs.getRowCount() == 0) 34 | incidentsJson += '{"y": '+parseInt(0, 10)+', "name": "'+grChanges.collected+'", "drilldown": "group1"},'; 35 | } 36 | changesJson = changesJson.slice(0,-1); 37 | changesJson += ']'; 38 | incidentsJson = incidentsJson.slice(0,-1); 39 | incidentsJson += ']'; 40 | 41 | changes = changes.join(','); 42 | times = times.join(','); 43 | incidents = incidents.join(','); 44 | 45 | 46 | 245 | 246 | 248 | 249 | 250 |
251 |
252 |
253 | 254 |
-------------------------------------------------------------------------------- /scheduled_jobs/license.js: -------------------------------------------------------------------------------- 1 | /* Tag users with a subscription, bucket (e.g. admin , fulfiller) and sub-bucket (e.g. corp, service desk, bot etc..) 2 | * Yes I know this is an abosulte mess! 3 | */ 4 | 5 | checkRoles(); 6 | 7 | function checkRoles() { 8 | gs.info("Processing ..."); 9 | try { 10 | var arrayUtil = new global.ArrayUtil(); 11 | var totalUsers = 0; 12 | var grUser = new GlideRecord("sys_user"); 13 | 14 | if (!grUser.isValidField('x_maim2_license_co_bucket')) { 15 | gs.info('The scheduled job "User Role Checker" cannot find the "type" field defined in the "sys_user" table'); 16 | return ; 17 | } 18 | grUser.addEncodedQuery('active=true^x_maim2_license_co_override_background_job=false'); 19 | //grUser.addQuery('sys_id', ''); //Used for testing purposes 20 | grUser.query(); 21 | while (grUser.next()) { 22 | 23 | totalUsers += 1; 24 | var theUser = grUser.sys_id; 25 | var theUserRoles = getRoles(theUser); // get an array of user roles 26 | var theCustomRoles = getCustomRoles(theUser); //temporary fix for array setup. Will clean up later AK. 27 | 28 | var roleCount= 0; 29 | if(theUserRoles){ 30 | roleCount = theUserRoles.length; // count how many roles the user has if not 'undefined' 31 | } 32 | 33 | 34 | var pCode = grUser.u_cai_user_projectcode; 35 | var region = grUser.u_region; 36 | 37 | 38 | //If the user has no roles, then they are a 'requester'. 39 | if (roleCount === 0) { 40 | 41 | grUser.x_maim2_license_co_bucket = ''; 42 | grUser.x_maim2_license_co_sub_bucket = ''; 43 | grUser.x_maim2_license_co_subscriptions = ''; 44 | grUser.update(); 45 | 46 | } else if (roleCount == 1 && arrayUtil.contains(theUserRoles, 'approver_user')) { 47 | grUser.x_maim2_license_co_bucket = 'approver'; 48 | grUser.x_maim2_license_co_subscriptions = 'global'; 49 | grUser.update(); 50 | continue; 51 | 52 | 53 | // If the user has multiple roles and one of them is 'admin', then they are an 'administrator'. 54 | } else if (roleCount > 0 && arrayUtil.contains(theUserRoles, 'admin') || arrayUtil.contains(theUserRoles, 'security_admin')) { 55 | grUser.x_maim2_license_co_subscriptions = 'global'; 56 | grUser.x_maim2_license_co_bucket = 'administrator'; 57 | if (grUser.sys_domain != '5dd48ebdd9fa21002d302841f239f1c9' /* CAI Home*/) {grUser.x_maim2_license_co_sub_bucket = 'sd';} 58 | if (region != ''){ 59 | switch(region.toLowerCase()){ 60 | case 'r3': 61 | grUser.x_maim2_license_co_sub_bucket = 'sd'; 62 | break; 63 | case 'r1': 64 | case 'r2': 65 | case 'corp': 66 | case 'msc': 67 | grUser.x_maim2_license_co_sub_bucket = 'hq'; 68 | 69 | } 70 | } if(grUser.x_maim2_license_co_bot){ 71 | grUser.x_maim2_license_co_sub_bucket = 'bot'; 72 | } if(grUser.x_maim2_license_co_snp){ 73 | grUser.x_maim2_license_co_sub_bucket = 'snp'; 74 | } 75 | if(arrayUtil.contains(theUserRoles, 'tracer')){ 76 | grUser.x_maim2_license_co_sub_bucket = 'tracer'; 77 | } 78 | 79 | grUser.update(); 80 | continue; 81 | 82 | // If the user has more than one role and did not have the 'admin' role, then they are a 'fulfiller'. 83 | } else if (roleCount == 1 && arrayUtil.contains(theUserRoles, 'custom')) { 84 | grUser.x_maim2_license_co_bucket = 'run_time'; 85 | grUser.update(); 86 | continue; 87 | 88 | // If none of the previous conditions were met, then consider the user as 'other'. 89 | } else if (roleCount == 1 && arrayUtil.contains(theUserRoles, 'certification')){ 90 | grUser.x_maim2_license_co_bucket = 'certification'; 91 | grUser.update(); 92 | continue; 93 | 94 | } else { 95 | if(roleCount > 0){ 96 | // check if the user is only using custom apps 97 | var coreRoles = []; 98 | var ionSalesRoles = []; 99 | var ionProcessRoles = []; 100 | var tracerRoles = []; 101 | var ionActionRoles = []; 102 | 103 | for(var i = 0; i < theCustomRoles.length; i++){ 104 | if(theCustomRoles[i].includes('x_mpaii_sales')){ 105 | ionSalesRoles.push(theCustomRoles[i]); 106 | } 107 | else if(theCustomRoles[i].includes('x_mpaii_process')){ 108 | ionProcessRoles.push(theCustomRoles[i]); 109 | } 110 | else if(theCustomRoles[i].includes('x_mpaii_aim') || theCustomRoles[i].includes('u_program_user')){ 111 | ionActionRoles.push(theCustomRoles[i]); 112 | } 113 | else if(theCustomRoles[i].includes('x_mpaii_tracer')){ 114 | tracerRoles.push(theCustomRoles[i]); 115 | } 116 | 117 | else if (theCustomRoles[i].includes('pa_viewer') || theCustomRoles[i].includes('u_asmdash_selfserv') || theCustomRoles[i].includes('CAI_Tracer') || theCustomRoles[i].includes('custom') || theCustomRoles[i].includes('sfa') || theCustomRoles[i].includes('tracer')) { 118 | continue; 119 | } else { 120 | coreRoles.push(theCustomRoles[i]); 121 | } 122 | 123 | 124 | } 125 | var core = parseInt(coreRoles.length); 126 | var sales = parseInt(ionSalesRoles.length); 127 | var process = parseInt(ionProcessRoles.length); 128 | var tracer = parseInt(tracerRoles.length); 129 | var action = parseInt(ionActionRoles.length); 130 | 131 | var obj = { 132 | 133 | c: {value: core, sub : 'global'}, 134 | s: {value: sales, sub : 'a23a6bd60f8e968045c63b8ce1050ed9'}, 135 | p: {value: process, sub : '07cdaa9a0f39c74045c63b8ce1050e2a'}, 136 | t: {value: tracer, sub : '1a1408b50198c200e8a1737744ce9899'}, 137 | a: {value: action, sub : '0be9ef1a0f8e968045c63b8ce1050e9f'} 138 | 139 | }; 140 | var subscriptions= []; 141 | 142 | for (var key in obj) { 143 | if (obj.hasOwnProperty(key)){ 144 | var value = obj[key].value; 145 | //gs.info(key + '----> ' + 'Sub ' + obj[key].sub + ' Value ' + obj[key].value); 146 | if(value > 0){ 147 | subscriptions.push(obj[key].sub); 148 | } 149 | 150 | } 151 | } 152 | grUser.x_maim2_license_co_subscriptions = subscriptions.join(','); 153 | grUser.x_maim2_license_co_bucket = 'fulfiller'; 154 | if (grUser.sys_domain != '5dd48ebdd9fa21002d302841f239f1c9' /* CAI Home*/) {grUser.x_maim2_license_co_sub_bucket = 'sd';} 155 | 156 | if(region != ''){ 157 | switch(region.toLowerCase()){ 158 | case 'r3': 159 | grUser.x_maim2_license_co_sub_bucket = 'sd'; 160 | break; 161 | case 'r1': 162 | case 'r2': 163 | case 'corp': 164 | case 'msc': 165 | grUser.x_maim2_license_co_sub_bucket = 'hq'; 166 | 167 | } 168 | } 169 | if(grUser.x_maim2_license_co_bot){ 170 | grUser.x_maim2_license_co_sub_bucket = 'bot'; 171 | } 172 | if(grUser.x_maim2_license_co_snp){ 173 | grUser.x_maim2_license_co_sub_bucket = 'snp'; 174 | } 175 | 176 | if(arrayUtil.contains(theUserRoles, 'sfa')){ 177 | grUser.x_maim2_license_co_sub_bucket = 'sfa'; 178 | } 179 | if(arrayUtil.contains(theUserRoles, 'tracer')){ 180 | grUser.x_maim2_license_co_sub_bucket = 'tracer'; 181 | } 182 | 183 | grUser.update(); 184 | } 185 | } 186 | } 187 | var t = new GlideDateTime().getDisplayValue(); 188 | gs.info("Processed " + totalUsers + " user records on " + t); 189 | 190 | } catch (e) { 191 | gs.info("Error in scheduled job 'User Role Checker' on line " + e.lineNumber + ": " + e); 192 | } 193 | } 194 | 195 | function getRoles(userId) { 196 | try { 197 | var selfServ = getSelfServ(); 198 | var sfaArray = getSFARoles(); 199 | var tracerArr = getTracerRoles(); 200 | var theRoles = []; 201 | var arrayUtil = new global.ArrayUtil(); 202 | 203 | var gr = new GlideRecord('sys_user_has_role'); 204 | gr.addQuery('user', userId); 205 | gr.query(); 206 | var theRoleName = ''; 207 | var index = ''; 208 | while (gr.next()) { 209 | if(gr.role != ''){ 210 | theRoleName = gr.role.name; 211 | theRoles.push(theRoleName.toString()); 212 | 213 | 214 | } 215 | } 216 | for(var i = 0; i < theRoles.length; i++){ 217 | if(arrayUtil.contains(selfServ, theRoles[i])){ 218 | theRoles[i] = 'custom'; 219 | } 220 | if(arrayUtil.contains(sfaArray, theRoles[i])){ 221 | theRoles[i] = 'sfa'; 222 | } 223 | if(arrayUtil.contains(tracerArr, theRoles[i])){ 224 | theRoles[i] = 'tracer'; 225 | } 226 | } 227 | 228 | 229 | 230 | return arrayUtil.unique(theRoles); 231 | } catch (e) { 232 | gs.info("Error in scheduled job 'User Role Checker > getRoles()' on line " + e.lineNumber + ": " + e); 233 | } 234 | } 235 | 236 | function getCustomRoles(userId){ 237 | var theRoles = []; 238 | var gr = new GlideRecord('sys_user_has_role'); 239 | gr.addQuery('user', userId); 240 | gr.query(); 241 | while(gr.next()){ 242 | theRoles.push(gr.role.name.toString()); 243 | } 244 | return theRoles; 245 | } 246 | 247 | 248 | function getSelfServ(){ 249 | var arr = []; 250 | var gr = new GlideRecord('x_maim2_license_co_run_time_role'); 251 | gr.query(); 252 | while(gr.next()){ 253 | arr.push(gr.role.name.toString()); 254 | 255 | } 256 | return arr; 257 | 258 | } 259 | function getSFARoles(){ 260 | var arr = []; 261 | var gr = new GlideRecord('sys_user_role'); 262 | gr.addEncodedQuery('nameSTARTSWITHx_mpaii_sfa'); 263 | gr.query(); 264 | while(gr.next()){ 265 | arr.push(gr.name.toString()); 266 | } 267 | 268 | return arr; 269 | 270 | } 271 | function getTracerRoles(){ 272 | var arr = []; 273 | var gr = new GlideRecord('sys_user_role'); 274 | gr.addEncodedQuery('nameSTARTSWITHx_mpaii_tracer'); 275 | gr.query(); 276 | while(gr.next()){ 277 | arr.push(gr.name.toString()); 278 | } 279 | 280 | return arr; 281 | } 282 | 283 | -------------------------------------------------------------------------------- /libraries/script_includes/catalogservices.js: -------------------------------------------------------------------------------- 1 | //author Bayview 2 | //functions for performing various tasks in the service catalog. Mainly workflow scripting 3 | 4 | var catalogServices = Class.create(); 5 | catalogServices.prototype = Object.extendsObject(AbstractAjaxProcessor, { 6 | airCardInventoryClient: function(){ 7 | var location = this.getParameter("sysparm_location"); 8 | var inventory = this.airCardInventory(location); 9 | return inventory; 10 | }, 11 | airCardInventory: function(location){ 12 | var inventory = 0; 13 | var itemCount = new GlideAggregate("u_loaner_air_cards"); 14 | itemCount.addQuery("u_location",location); 15 | itemCount.addEncodedQuery("u_request_itemISEMPTY"); 16 | itemCount.addAggregate("COUNT"); 17 | itemCount.query(); 18 | while (itemCount.next()){ 19 | inventory = itemCount.getAggregate("COUNT"); 20 | } 21 | return inventory; 22 | }, 23 | userHasAircard: function(){ 24 | var userID = this.getParameter("sysparm_user"); 25 | var aircard_count = 0; 26 | var rtnValue = "false"; 27 | var aircard = new GlideAggregate("u_loaner_air_cards"); 28 | aircard.addEncodedQuery("u_request_item.active=true^u_request_item.request.requested_for="+userID); 29 | aircard.addAggregate("COUNT"); 30 | aircard.query(); 31 | while (aircard.next()){ 32 | aircard_count = aircard.getAggregate("COUNT"); 33 | } 34 | if (aircard_count > 0){ 35 | rtnValue = "true"; 36 | } 37 | return rtnValue; 38 | }, 39 | getAircardNumber: function (ritm){ 40 | var aircardID = ""; 41 | var aircard = new GlideAggregate("u_loaner_air_cards"); 42 | aircard.addQuery("u_request_item",ritm); 43 | aircard.query(); 44 | while (aircard.next()){ 45 | aircardID = aircard.sys_id; 46 | } 47 | return aircardID; 48 | }, 49 | releaseAircard: function(ritm){ 50 | var aircard = new GlideAggregate("u_loaner_air_cards"); 51 | aircard.addQuery("u_request_item",ritm); 52 | aircard.query(); 53 | while (aircard.next()){ 54 | aircard.u_request_item = ''; 55 | aircard.update(); 56 | } 57 | }, 58 | 59 | loanerLaptopInventoryClient: function(){ 60 | var location = this.getParameter("sysparm_location"); 61 | var inventory = this.loanerLaptopInvetory(location); 62 | return inventory; 63 | }, 64 | loanerLaptopInvetory: function(location){ 65 | var inventory = 0; 66 | var itemCount = new GlideAggregate("u_loaner_laptops"); 67 | itemCount.addQuery("u_location",location); 68 | itemCount.addEncodedQuery("u_request_itemISEMPTY"); 69 | itemCount.addAggregate("COUNT"); 70 | itemCount.query(); 71 | while (itemCount.next()){ 72 | inventory = itemCount.getAggregate("COUNT"); 73 | } 74 | return inventory; 75 | }, 76 | userHasLoanerLaptop: function(){ 77 | try{ 78 | var userID = this.getParameter("sysparm_user"); 79 | var laptop_count = 0; 80 | var rtnValue = "false"; 81 | var laptop = new GlideRecord("u_loaner_laptops"); 82 | laptop.addEncodedQuery("u_request_item.active=true^u_request_item.request.requested_for="+userID); 83 | laptop.query(); 84 | while (laptop.next()){ 85 | rtnValue = "true"; 86 | } 87 | return rtnValue; 88 | }catch(ex){ 89 | gs.log(ex.message); 90 | } 91 | }, 92 | getLaptopNumber: function (ritm){ 93 | var laptopID = ""; 94 | var laptop = new GlideAggregate("u_loaner_laptops"); 95 | laptop.addQuery("u_request_item",ritm); 96 | laptop.query(); 97 | while (laptop.next()){ 98 | laptopID = laptop.sys_id; 99 | } 100 | return laptopID; 101 | }, 102 | releaseLaptop: function(ritm){ 103 | var laptop = new GlideAggregate("u_loaner_laptops"); 104 | laptop.addQuery("u_request_item",ritm); 105 | laptop.query(); 106 | while (laptop.next()){ 107 | laptop.u_request_item = ''; 108 | laptop.update(); 109 | } 110 | }, 111 | loanerProjectorInventoryClient: function(){ 112 | var location = this.getParameter("sysparm_location"); 113 | var inventory = this.loanerProjectorInvetory(location); 114 | return inventory; 115 | }, 116 | loanerProjectorInvetory: function(location){ 117 | var inventory = 0; 118 | var itemCount = new GlideAggregate("u_loaner_projectors"); 119 | itemCount.addQuery("u_location",location); 120 | itemCount.addEncodedQuery("u_request_itemISEMPTY"); 121 | itemCount.addAggregate("COUNT"); 122 | itemCount.query(); 123 | while (itemCount.next()){ 124 | inventory = itemCount.getAggregate("COUNT"); 125 | } 126 | return inventory; 127 | }, 128 | userHasLoanerProjector: function(){ 129 | try{ 130 | var userID = this.getParameter("sysparm_user"); 131 | var projector_count = 0; 132 | var rtnValue = "false"; 133 | var projector = new GlideRecord("u_loaner_projectors"); 134 | projector.addEncodedQuery("u_request_item.active=true^u_request_item.request.requested_for="+userID); 135 | projector.query(); 136 | while (projector.next()){ 137 | rtnValue = "true"; 138 | } 139 | return rtnValue; 140 | }catch(ex){ 141 | gs.log(ex.message); 142 | } 143 | }, 144 | getProjectorNumber: function (ritm){ 145 | var projectorID = ""; 146 | var projector = new GlideAggregate("u_loaner_projectors"); 147 | projector.addQuery("u_request_item",ritm); 148 | projector.query(); 149 | while (projector.next()){ 150 | projectorID = projector.sys_id; 151 | } 152 | return projectorID; 153 | }, 154 | releaseProjector: function(ritm){ 155 | var projector = new GlideAggregate("u_loaner_projectors"); 156 | projector.addQuery("u_request_item",ritm); 157 | projector.query(); 158 | while (projector.next()){ 159 | projector.u_request_item = ''; 160 | projector.update(); 161 | } 162 | }, 163 | getSupportGroup: function(location, type){ 164 | var rec = new GlideRecord('u_location_support_groups'); 165 | var grpSysid = ''; 166 | rec.addQuery('u_location.sys_id',location); 167 | rec.query(); 168 | while (rec.next()){ 169 | if (rec.u_group.type.getDisplayValue() == type){ 170 | grpSysid = rec.u_group.sys_id; 171 | } 172 | } 173 | return grpSysid; 174 | }, 175 | getServiceDesk:function(){ 176 | var sdId; 177 | var group = new GlideRecord("sys_user_group"); 178 | group.addEncodedQuery("name=Service Desk"); 179 | group.query(); 180 | while (group.next()){ 181 | sdId = group.sys_id; 182 | } 183 | return sdId; 184 | }, 185 | getAssignmentGroup: function (location){ 186 | var groupID = ""; 187 | var cmnLocation = new GlideRecord("cmn_location"); 188 | if (cmnLocation.get(location)){ 189 | if (cmnLocation.name == "Coral Gables, FL"){ 190 | groupID = this.getServiceDesk(); 191 | }else{ 192 | groupID = this.getSupportGroup(location,"Desktop Support"); 193 | } 194 | } 195 | if (groupID == ""){ 196 | groupID = this.getServiceDesk(); 197 | } 198 | return groupID; 199 | }, 200 | getLocationAircads: function(task_id){ 201 | var aircard_id =""; 202 | var task = new GlideRecord("sc_task"); 203 | if (task.get(task_id)){ 204 | var location = task.request_item.u_physical_office; 205 | var aircard = new GlideRecord("u_loaner_air_cards"); 206 | aircard.addQuery("u_location",location); 207 | aircard.addEncodedQuery("u_request_itemISEMPTY"); 208 | aircard.query(); 209 | while (aircard.next()){ 210 | aircard_id += ","+aircard.sys_id; 211 | } 212 | } 213 | return 'sys_idIN'+aircard_id; 214 | }, 215 | getLocationLaptops: function(task_id){ 216 | var laptop_id =""; 217 | var task = new GlideRecord("sc_task"); 218 | if (task.get(task_id)){ 219 | var location = task.request_item.u_physical_office; 220 | var laptop = new GlideRecord("u_loaner_laptops"); 221 | laptop.addQuery("u_location",location); 222 | laptop.addEncodedQuery("u_request_itemISEMPTY"); 223 | laptop.query(); 224 | while (laptop.next()){ 225 | laptop_id += ","+laptop.sys_id; 226 | } 227 | } 228 | return 'sys_idIN'+laptop_id; 229 | }, 230 | getLocationProjectors: function(task_id){ 231 | var projector_id =""; 232 | var task = new GlideRecord("sc_task"); 233 | if (task.get(task_id)){ 234 | var location = task.request_item.u_physical_office; 235 | var projector = new GlideRecord("u_loaner_laptops"); 236 | projector.addQuery("u_location",location); 237 | projector.addEncodedQuery("u_request_itemISEMPTY"); 238 | projector.query(); 239 | while (projector.next()){ 240 | projector_id += ","+projector.sys_id; 241 | } 242 | } 243 | return 'sys_idIN'+laptop_id; 244 | }, 245 | ritmVariableInfo: function(ritm_id){ 246 | var misc = 'Additional Info: ' + "
"; 247 | var itemVars = new GlideRecord('sc_item_option_mtom'); 248 | itemVars.addQuery("request_item",ritm_id); 249 | itemVars.addEncodedQuery("sc_item_option.item_option_newISNOTEMPTY^sc_item_option.valueISNOTEMPTY^sc_item_option.value!=false^sc_item_option.item_option_new.name!=requested_for^ORsc_item_option.item_option_new.name=NULL^sc_item_option.item_option_new.name!=delivery_time"); 250 | itemVars.query(); 251 | while (itemVars.next()){ 252 | var variable_name = itemVars.sc_item_option.item_option_new.name; 253 | var label = itemVars.sc_item_option.item_option_new.sys_name; 254 | var var_value = itemVars.sc_item_option.value; 255 | if (variable_name == 'approver_user'){ 256 | var userObject = new UserAjax(); 257 | var_value = userObject.getUserName(var_value); 258 | } 259 | misc += ''+label+ ': ' + var_value + '
'; 260 | 261 | } 262 | return misc; 263 | }, 264 | getExecutiveApprovers: function(){ 265 | var sys_id = ''; 266 | var approvers = new GlideRecord("u_approver_list"); 267 | approvers.addEncodedQuery("u_display_record=true^u_user.active=true"); 268 | approvers.query(); 269 | while(approvers.next()){ 270 | sys_id += approvers.u_user.sys_id +","; 271 | } 272 | return 'sys_idIN'+sys_id; 273 | }, 274 | processItemApprovals: function(request,approval_value){ 275 | var item = new GlideRecord("sc_req_item"); 276 | item.addQuery("request",current.sys_id); 277 | item.query(); 278 | while (item.next()){ 279 | var approval = new GlideRecord("sysapproval_approver"); 280 | approval.addQuery("sysapproval",item.sys_id); 281 | approval.addQuery("state","requested"); 282 | approval.query(); 283 | while (approval.next()){ 284 | approval.state = approval_value; 285 | approval.update(); 286 | } 287 | } 288 | }, 289 | type: 'catalogServices' 290 | }); 291 | --------------------------------------------------------------------------------