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({   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 ( {     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); })();

Broadcast an event to workflow!/api_doc?v=jakarta&id=r_WF-broadcastEvent_S_S

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   -o 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

Blank Strings Regex Check

//--blank strings var inValid = new RegExp("[\\s]"); var bres= inValid.test("thisisatest"); gs.print(bres);

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         //--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');