syntax_editor_macros

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
syntax_editor_macros [03/16/2026 09:04] – [s_MailScript] johnsonjohnsyntax_editor_macros [03/16/2026 11:21] (current) johnsonjohn
Line 1: Line 1:
 ======Syntax Editor Macros====== ======Syntax Editor Macros======
 +==Also located in downloads==
 ---- ----
 +
 +====Network Location====
 +<code javascript networkLocation.js>
 +// ADFS with Imprivata MFA should be used to leverage a network location claim
 +// into SNOW, enabling role based PHI visibility and control.
 +gs.getSession().getProperty("PHI_access_Role");
 +</code>
 +----
 +
 +====doc====
 +<code javascript doc.js>
 +/** 
 +* Description: $0 
 +* Parameters:  
 +* Returns:
 +*/ 
 +</code>
 +----
 +
 +====for====
 +<code javascript for.js>
 +for (var i=0; i< myArray.length; i++) {
 +    //myArray[i]; 
 +}
 +</code>
 +----
 +
 +====info====
 +<code javascript info.js>
 +gs.addInfoMessage(gs.getMessage("$0"));
 +</code>
 +----
 +
 +====vargr====
 +<code javascript vargr.js>
 +var gr = new GlideRecord("$tableName");
 +gr.addQuery("name", "value");
 +gr.query();
 +if (gr.next()) {   
 +}
 +</code>
 +----
 +
 +====vargror====
 +<code javascript vargror.js>
 +var gr = new GlideRecord('$tableName'); 
 +var qc = gr.addQuery('field', 'value1'); 
 +qc.addOrCondition('field', 'value2');
 +gr.query(); 
 +while (gr.next()) {
 + 
 +}
 +</code>
 +----
 +
 =====Client-Side Key Concepts===== =====Client-Side Key Concepts=====
 ====JWJ==== ====JWJ====
Line 6: Line 62:
 //name jwj //name jwj
 //Text //Text
 +//Client-Side Key Concepts
 +//default
 +doc
 +for 
 +info 
 +vargr 
 +vargror
 +
 //Client-Side Key Concepts //Client-Side Key Concepts
 c_GeneratingMessages c_GeneratingMessages
Line 14: Line 78:
 c_ScratchpadDatabaseAccess c_ScratchpadDatabaseAccess
 c_TryBlock c_TryBlock
- +
 //Server-Side Key Concepts //Server-Side Key Concepts
 s_AjaxFunctionDefinition s_AjaxFunctionDefinition
Line 593: Line 657:
  template.print(sAnchorTag);  template.print(sAnchorTag);
 })(current, template, email, email_action, event); })(current, template, email, email_action, event);
 +</code>
 +----
 +
 +====s_Object====
 +<code javascript s_Object.js>
 +//object, property definition, function definition, stringify(), dot Notation, bracket notation with quotes, testing for properties, for loop with in operator, method calls, JSON.parse(), 
 +//https://www.w3schools.com/js/js_objects.asp
 +
 +//An object is a built-in data type for storing properties (key-value pairs).
 +//Data inside an object is unordered, and the values can be of any type.
 +var apple ={
 + color: "Green",
 + family: "Fruit",
 + price: "$3/kg",
 + method1: function(arg1, arg2){
 + return arg1 + arg2 + this.color;
 + }
 +};
 +
 +gs.addInfoMessage(JSON.stringify(apple)); //This will show: {"color":"Green,"family":"Fruit","price:"$3/kg" Note that methods are not listed.
 +gs.addInfoMessage("apple:color: " + apple.color);  //Use dot notation to reference individual values.
 +gs.addInfoMessage('apple["color]": ' + apple["color"]); //You may also use bracket notation and key names within quotes
 +if (apple.bogusKey) 
 + gs.addInfoMessage(apple.bogusKey); //An if statement can be ued to test for undefined properties.
 +gs.addInfoMessage("Listing properties of apple via for loop, including methods:");
 +
 +for (var appleKey in apple){ 
 + gs.addInfoMessage(appleKey + " : " + apple[appleKey]);
 +}
 +gs.addInfoMessage("Method call result:");
 +gs.addInfoMessage( apple.method1(5, 10)); //Example method call.
 +
 +//Creating an object from a string.
 +var sObject = '{ "size":"Large", "color":"Red", "age":"Old" }';
 +var myObject = JSON.parse(sObject);
 +gs.addInfoMessage("Listing properties of myObject via for loop:");
 +for (var myObjectKey in myObject){
 + gs.addInfoMessage(myObjectKey + " : " + myObject[myObjectKey]);
 +}
 </code> </code>
 ---- ----
  
 ====s_ScratchpadPopulation==== ====s_ScratchpadPopulation====
-<code>+<code javascript s_ScratchpadPopulation.js> 
 +//g_scratchpad
  
 +//Since client side AJAX code may be slow as it involves asynchronous round trips to the server, a special object called g_scratchpad may be used instead.
 +//Any "display" type business rule may proactively fill the g_scratchpad object with data which will be available for use on the client.
 +//Context: Business Rule of type "Display".
 +
 +//Populate the scratchpad from server side code…
 +(function executeRule(current, previous /*null when async*/) {
 + g_scratchpad.MyOwnVariable = "XYZ";
 +})(current, previous);
 </code> </code>
 ---- ----
  
 ====s_SetRedirectURLFunction==== ====s_SetRedirectURLFunction====
-<code>+<code javascript s_SetRedirectURLFunction.js> 
 +//setRedirectURL(), Debug Now
  
 +//This custom UI Action, "Debug Now" executs "Scheduled Script Execution" scripts (from table "sysauto_script") in the current session.
 +//Execution in the current session allows the script debugger (and breakpoints) to be used, and lets you see client side messages such as infoMessages.
 +try{
 + var evaluator = new GlideScopedEvaluator();  
 + evaluator.evaluateScript(current, 'script');
 + action.setRedirectURL(current);
 +}
 +catch(e){
 + gs.addInfoMessage(e);
 +}
 </code> </code>
 ---- ----
  
 ====s_TryBlock==== ====s_TryBlock====
-<code>+<code javascript s_TryBlock.js> 
 +//Single LIne Try Catch Block.  Catches errors such as use of undefined functions or methods, or attempting to reference fields of a null object. 
 +try { RunServerSideCustomCode(); } catch(err){ var s = "Error caught by catch block: " + err.toString(); gs.error(s); gs.addErrorMessage(s); }
  
 +function RunServerSideCustomCode(){
 + //Write custom code here...
 + null.MyInvalidFunctionCall();
 +}
 </code> </code>
 ---- ----
  • syntax_editor_macros.1773677048.txt.gz
  • Last modified: 06/28/2026 16:38
  • (external edit)