update_sets

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
update_sets [01/13/2026YYY 05:16] – [JWJ Onboarding Catalog Item] johnsonjohnupdate_sets [01/13/2026YYY 06:01] (current) johnsonjohn
Line 4295: Line 4295:
 </unload> </unload>
 </code> </code>
 +----
 +
 +===== UI Script to Enable Syntax Editor Macros =====
 +<code xml enableUISyntaxEditor.xml>
 +<!--  JWJ0215 10-15-18 -->
 +<?xml version="1.0" encoding="UTF-8"?>
 +<unload unload_date="2018-10-15 18:33:11">
 +<sys_ui_script action="INSERT_OR_UPDATE">
 +<active>true</active>
 +<description/>
 +<global>false</global>
 +<name>widgetMacros</name>
 +<script><![CDATA[(function(){
 + 
 +  //object to store macros in
 +  var macrosObj={
 +  };
 + 
 +  var fn = function(e){
 +    var keyCode = e.keyCode || e.which;
 +   
 +    //check if key pressed is TAB
 +    if (keyCode == 9) {
 +     
 +      //get DOM element for active pane
 +      var cmEl = jQuery(document.activeElement).parents('.CodeMirror')[0];
 +     
 +      //get CodeMirror object for active pane. CodeMirror is the Syntax Editor library used in the Widget Editor
 +      var cmObj = cmEl.CodeMirror;
 +     
 +      //get position of cursor and end of line
 +      var tmpCursor=cmObj.getCursor();
 +      var eol=cmObj.getLine(tmpCursor.line).length;
 +     
 +      //do nothing if cursor is not at end of line
 +      //this allows users to continue using TAB key for formatting/indentation
 +      if(tmpCursor.ch < eol){
 +        return true;
 +      }
 +     
 +      //do nothing if any text is selected
 +      if(cmObj.somethingSelected()){
 +        return true;
 +      }
 +     
 +      //find the start and end position of the word preceeding the cursor
 +      var wordObj = cmObj.findWordAt({
 +        line: tmpCursor.line,
 +        ch: tmpCursor.ch-2
 +      });
 +     
 +      //get the actual word preceeding the cursor
 +      var word = cmObj.getRange(wordObj.anchor, wordObj.head);
 +     
 +      //do nothing if a corresponding Syntax Editor Macro does not exist
 +      if(typeof macrosObj[word]==='undefined')
 +        return true;
 +     
 +      //select the word preceeding the cursor
 +      var sel = cmObj.setSelection(wordObj.anchor,wordObj.head);
 +     
 +      //replace selection with the text of the Syntax Editor Macro
 +      cmObj.replaceSelection( macrosObj[word].text );
 +    }
 +  };
 + 
 +  //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);
 +})();]]></script>
 +<script_name/>
 +<sys_class_name>sys_ui_script</sys_class_name>
 +<sys_created_by>JWJ0215</sys_created_by>
 +<sys_created_on>2018-10-15 18:33:05</sys_created_on>
 +<sys_id>0c48caef0fc5e3008d10982be1050e38</sys_id>
 +<sys_mod_count>0</sys_mod_count>
 +<sys_name>widgetMacros</sys_name>
 +<sys_package display_value="Global" source="global">global</sys_package>
 +<sys_policy/>
 +<sys_scope display_value="Global">global</sys_scope>
 +<sys_update_name>sys_ui_script_0c48caef0fc5e3008d10982be1050e38</sys_update_name>
 +<sys_updated_by>JWJ0215</sys_updated_by>
 +<sys_updated_on>2018-10-15 18:33:05</sys_updated_on>
 +<ui_type>0</ui_type>
 +<use_scoped_format>false</use_scoped_format>
 +</sys_ui_script>
 +</unload>
 +</code>
 +
 ---- ----
  
  • update_sets.1768310186.txt.gz
  • Last modified: 01/13/2026YYY 05:16
  • by johnsonjohn