Execute powershell script from ServiceNow workflow run script activity

var pScript = “Script that needs to be executed”; var powershell = new PowershellProbe(‘MID_SERVER_NAME’, gs.getProperty(‘mid.server.ip’)); powershell.setScript(pScript); var resp = powershell.execute(true); workflow.scratchpad.error = resp.error; workflow.scratchpad.output = resp.output; if(!resp.output.nil() && resp.output ! = ‘null’) current.work_notes = resp.output; else if(!resp.error.nil()) { current.work_notes = ‘Error in script:  ‘ + resp.error; } gs.log(‘Response Output ‘ + resp.output); gs.log(‘Response Error ‘ […]

Script to add variables to catalog item created through run script in workflow

var reqvar = new GlideRecord(‘sc_item_option_mtom’); reqvar.addQuery(‘request_item’,current.sys_id); reqvar.query(); while (reqvar.next()) { var variablereference = new GlideRecord(‘sc_item_option’); if (variablereference.get(reqvar.sc_item_option)) { var add_task_var = new GlideRecord(‘sc_item_variables_task’); add_task_var.task = tsk_sys_id; add_task_var.variable = variablereference.item_option_new; add_task_var.insert(); } }