Skip to content

Instantly share code, notes, and snippets.

@meinzeugde
Last active June 6, 2018 20:59
Show Gist options
  • Save meinzeugde/983aa171eecd21c9f516542eeea8cb02 to your computer and use it in GitHub Desktop.
Save meinzeugde/983aa171eecd21c9f516542eeea8cb02 to your computer and use it in GitHub Desktop.
Execute Background Script from Client Script: Retrieve SysID
var sysId = 'someSysId';
var gck = typeof g_ck != 'undefined' ? g_ck : 'insertOptionalTokenHere'; //if AppNavigator is shown, it is retrieved automatically
jQuery.ajax({
url: 'sys.scripts.do',
method: 'GET', //POST does not work somehow
headers: {
'X-UserToken': gck,
'Cache-Control': 'no-cache',
'Accept': 'application/json',
'Content-Type': 'application/json'
},
data: {
script: 'function findSysID(e){var s,d,n=new GlideRecord("sys_db_object");n.addEncodedQuery("super_class=NULL^nameNOT LIKEts_^nameNOT LIKEsysx_^nameNOT LIKEv_^sys_update_nameISNOTEMPTY^nameNOT LIKE00"),n.query();for(var a=[];n.next();)d=n.name+"",(s=new GlideRecord(d)).isValid()&&(s.addQuery("sys_id",e),s.queryNoDomain(),s.setLimit(1),s.query(),s.hasNext()&&a.push(d));gs.print("###"+a+"###")}findSysID("'+sysId+'");',
runscript: "Run script",
sysparm_ck: gck,
sys_scope: 'e24e9692d7702100738dc0da9e6103dd'
}
}).done(function (rspns) {
answer = rspns.match(/###(.*)###/);
console.log(answer != null ? answer[1] : rspns);
}).fail(function (jqXHR, textStatus) {
console.error(textStatus);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment