diff --git a/Service Portal/spOnReady/readme.md b/Service Portal/spOnReady/readme.md new file mode 100644 index 0000000..c72d290 --- /dev/null +++ b/Service Portal/spOnReady/readme.md @@ -0,0 +1,3 @@ +This syntax macro Get data from the background and make it accessible after it is retrieved. + +e.g This macro can be used from client script during service portal widget development. diff --git a/Service Portal/spOnReady/sp_onready.js b/Service Portal/spOnReady/sp_onready.js new file mode 100644 index 0000000..a690fa4 --- /dev/null +++ b/Service Portal/spOnReady/sp_onready.js @@ -0,0 +1,27 @@ +//add keyup event listener + jQuery(window).on('keyup', fn); + + //populate macrosObj with records from the Syntax Editor Macro table + var requestBody = ""; + var client=new XMLHttpRequest(); + client.open("get","/api/now/table/syntax_editor_macro?sysparm_fields=name%2Ctext"); + + client.setRequestHeader('Accept','application/json'); + client.setRequestHeader('Content-Type','application/json'); + client.setRequestHeader('X-UserToken',window.g_ck); + + var rsc = function(){ + if(this.readyState == this.DONE) { + var rspObj=JSON.parse(this.response).result; + for(var macro in rspObj){ + if(!rspObj.hasOwnProperty(macro)) + continue; + + var currentMacro=rspObj[macro]; + macrosObj[currentMacro.name]=currentMacro; + } + } + }; + + client.onreadystatechange = rsc; + client.send(requestBody);