Skip to main content

Posts

Showing posts from December, 2018

Post a command to the ECC queue for the mid server to initiate a powershell file copy

try{ var grECCQ=new GlideRecord('ecc_queue'); grECCQ.newRecord(); grECCQ.agent='mid.server.' + gs.getProperty('mid.server.rba_default'); grECCQ.topic='Command'; grECCQ.queue='output'; grECCQ.state='ready'; var sSourcePath=gs.getProperty('basefilepath.source') + current.variables.foldername; var sTargetPath=gs.getProperty('basefilepath.target'); var sCommand='Powershell.exe Move-Item ' + '"' + sSourcePath + '" -Destination' + ' ' + '"' + sTargetPath + '"'; grECCQ.name=sCommand; grECCQ.insert() workflow.scratchpad.copycommand= grECCQ.name; workflow.scratchpad.eccq_sysid=grECCQ.insert(); var sLogMsg=Copy Command posted to ECC queue: \n'; sLogMsg+='/nav_to.do?uri=ecc_queue.do?sys_id='+workflow.scratchpad.eccq_sysid; gs.log(sLogMsg, 'wf:runScriptLogs'); }catch (ex){ gs.logError('ERROR:: ' + cu

parse the ECC Q for an error

var grECCQ=new GlideRecord('ecc_queue'); sysid='2d616f684f2d2700ddd0ecd18110c71c'; if (grECCQ.get('sys_id', sysid)){    var pl_xml=new XMLDocument(grECCQ.payload); var inodes= pl_xml.getNodes("//parameter"); for (x=0;x<inodes.length;x++){ //gs.print(inodes.item(x).getAttribute('name') + '::: ' + inodes.item(x).getAttribute('value')); var sname=inodes.item(x).getAttribute('name'); if (sname=='error_string'){    sValue=inodes.item(x).getAttribute('value');   gs.print('sValue=' + sValue);    if (sValue!=''){         gs.print('ERR!!');    } } } var sErrChk2=pl_xml.getNodeText("//error"); gs.print(sErrChk2); }

UI Macro to display CIs assigned to a user

<?xml version="1.0" encoding="utf-8" ?> <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">   Assets currently assigned to this user: <a href='' onclick="event.preventDefault();showdiag();">click here</a> <script>   function showdiag(){   var req_for=g_form.getValue('var_requested_for');   if (req_for!=''){ var dialog = new GlideDialogWindow('show_list'); dialog.setTitle('Assets assigned to user'); dialog.setPreference('table', 'cmdb_ci_list'); dialog.setPreference('sysparm_view', 'default'); var query = 'assigned_to=' + req_for; dialog.setPreference('sysparm_query', query);         dialog.render();   } }

URL stuff

//get entire url: var instanceURL = GlideTransaction.get().getRequest().getHeader("referer"); //get bit of a url: var surl='https://dev.service-now.com/hr/case_detail.do?sysparm_case=210ebaf74f82ef00aaa42c518110c7a9& sysparm_newcase=true &sysparm_nameofstack=250efaf74f82ef00aaa42c518110c705'; //--bit between 'sysparm_newcase' and '&' var testRE = surl.match("sysparm_newcase=(.*)&"); gs.print(testRE);

UI Macro containing an external url link

<?xml version="1.0" encoding="utf-8" ?> <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">   <b style = "color: #DD3197" >Data Protection</b><br/> Company is committed to protecting the privacy and security of your personal information. <a href='' onclick="event.preventDefault();gdprRef('${gs.getMessage('gdpr')}');">privacy notice</a> sets out how we process your data. <script>   var myGDPRWindow; function gdprRef(url){ if(g_form.modified){ g_form.modified=false; } var res=confirm('Do you wish to view the privacy notice?'); if (res){      myGDPRWindow=window.open(url, "s", "resizable=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, copyhistory=no").blur();       g_form.modified=true; /

skip business rules, last updated, notifications

current.autoSysFields(false);//--leave last updated intact current.setWorkflow(false); //--skip business rules and notifications current. setEngines ( false ) ; //--skip data policy rules var grEmails = new GlideRecord ( 'sys_email' ); grEmails . addQuery ( 'type' , 'send-ready' ); grEmails . setValue ( 'type' , 'send-ignored' ); grEmails . updateMultiple ();

Re-starting a workflow

var gr = new GlideRecord('wf_context'); gr.addQuery("id", current.sys_id); gr.addInactiveQuery(); gr.addQuery("name","<workflow name>"); gr.query(); if (gr.next()){ gs.addInfoMessage('restarting "<workflow name>" workflow'); var wflw = new Workflow(); wflw.startFlow(wflw.getWorkflowFromName('<workflow name>'), current, 'update'); }