Skip to main content

Posts

Showing posts from March, 2020

Service Portal Widgets: Clear html fields in portal widget in client script

<br/><br/><button ng-click="clearFields()" class="btn btn-danger action-btn pull-left">Click to reset fields</button> <textarea id='results_q' rows="10" cols="100">{{c.duplrecordsList}}</textarea> ---------- function($scope) {   /* widget controller */   var c = this; $scope.clearFields = function() {         //console.log("message", 'run the op');                document.getElementById("tbl_name").value='';                                     document.getElementById("dupl_field").value='';                                     document.getElementById("custom_query").value=''; //--on a textarea: c.duplrecordsList='';                                       }; }

Navigate to history entry from ui action

slightly clunky way and perhaps not ideal, but it works navigate to the history entry. the sysid corresponds to the id of the record changed var grSHS=new GlideRecord('sys_history_set');//--record history if (grSHS.get('id', '8cf2d354db733f403c304662159619a2')){ var grSHL=new GlideRecord('sys_history_line');//--history grSHL.addQuery('field', 'assignment_group'); //--or whatever field has changed grSHL.addQuery('set', grSHS.sys_id); grSHL.addQuery('oldISNOTEMPTY^newISNOTEMPTY'); grSHL.orderBy('sys_created_on'); grSHL.query(); while(grSHL.next()){   gs.print(grSHL.sys_id);   gs.print(grSHL.old);   gs.print(grSHL.old_value); } } //--or in a script include: call it this way: gs.print(si.getAuditHistory_previousValue('8cf2d354db733f403c304662159619a2', 'assignment_group')); getAuditHistory_previousValue: function(SYSID, FIELD_CHANGED){                   

Reset group approval UI ACTION

set the UI action as 'client' script: function trigger_new_approval_ritm(){                 var res=confirm(getMessage(ritm.changeapprovalgrp'));                 if (res){                                 alert(getMessage(‘ritm.approvalgroup.resendemails'));                                 gsftSubmit(null, g_form.getFormElement(), 'resend_email'); //--MUST call the 'Action name' set in this UI Action                 } } if (typeof window == 'undefined'){                 resend_approval(); } function resend_approval(){                 var grRITM=new GlideRecord('sc_req_item');                 if (grRITM.get('sys_id', current.parent)){                                 var grApprGrp=new GlideRecord('sysapproval_group');                                 grApprGrp.newRecord();                                 grApprGrp.parent=current.parent;                                 grApprGrp.

Write data to CSV

(function executeRule() {   var grCI = new GlideRecord('cmdb_ci');   grCI.addNotNullQuery('x_tori2_addm_key');   grCI.query();   var dataStr = 'name,x_tori2_addm_key,sys_id,sys_class_name\n';   while (grCI.next()) {     dataStr += grCI.getValue('name') + ','     + grCI.getValue('x_tori2_addm_key') + ','     + grCI.getUniqueValue() + ','     + grCI.getValue('sys_class_name') + '\n';   }   var user = new GlideRecord('sys_user');   user.get(gs.getUserID());   var gsa = new GlideSysAttachment();   gsa.write(user, 'uControl.csv', 'text/csv', dataStr); })();

ServiceNow Broadcast an event to workflow

ServiceNow Broadcast an event to workflow https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_WF-broadcastEvent_S_S   https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/c_WorkflowAPI#r_WF-broadcastEvent_S_S   /where current is a task record with a workflow context var wf = new Workflow().getRunningFlows(current); while (wf.next()) { new Workflow().broadcastEvent(wf.sys_id, 'resume' ); }

Working with Linux MID Servers

some useful UNIX commands e.g. via Putty downloading the agent folder for a manual MID server upgrade: use curl url curl https://install.service-now.com/glide/distribution/builds/package/mid/2019/11/28/mid.newyork-06-26-2019__patch4-11-21-2019_11-28-2019_1046.linux.x86-64.zip   -o madridpatch9.zip MID Server Stop/Start/Status commands stop the MID server: using command sudo /usr/bin/systemctl stop mid start the MID server: using command sudo /usr/bin/systemctl start mid status of MID: /usr/bin/systemctl status mid rename the agent folder to old_agent using: mv agent old_agent_nov2019 delete operations delete folder and contents: rm -rf <folder_name> delete file: rm <file_name> restore backup files navigate to the folder run commands to restore backup files: cp config.xml /app/midserver/agent/ cp wrapper-override.conf /app/midserver/agent/conf/ cp agent_keystore.jks /app/midserver/agent/keystore/ cp

Building up a scripted REST api list of catalog tasks plus their variables

called via scripted rest endpoint script include logic: ======================= getOpenRequests: function() {         //--Courtesy of  https://snprotips.com/blog/2016/7/15/scripted-rest-apis-in-servicenow-how-to-retrieve-catalog-item-variables         //--done this way due to issues with gliderecord/memory leakage!!         var responseObj = {};                 try {             //gs.log('1:' + this.LINUX_SERVER_REQ);             /*test it this way:                var si= new _ansible_servicerequest();                var sRes= si.getOpenRequests()                gs.print('result:\n ' +JSON.stringify(sRes));             */             var itemSYSID = this.LINUX_SERVER_REQ;             var grTasks = new GlideRecord('sc_task');             grTasks.addActiveQuery();             grTasks.addQuery('request_item.cat_item=' + itemSYSID);                                                 grTasks.orderBy('number');