├── .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 |
5 | - Transform Scripts
6 | - Catalog Client Scripts
7 | - Background Scripts
8 | - Business Rules
9 |
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 |
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+="