Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

DOM manipulation

reddys
Kilo Contributor

Can anyone suggest replacement functions for DOM manipulation technique (e.g., jQuery, Prototype JS($ or $$), gel, document) in Client script and Catalog client scripts

function getParmVal(name){

      var url = document.URL.parseQuery();

      if(url[name]){

              return decodeURI(url[name]);

      }

      else{

              return '';

      }

}

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

Sample function:



var gURL = new GlideURL();


gURL.setFromCurrent();


alert(gURL.getParam("sysparm_id"));



where sysparm_id is the parameter that needs to be read from URL.


View solution in original post

4 REPLIES 4

amaradiswamy
Kilo Sage

Hi Sanjeev,



One of the method i know is if i want to add an image beside the caller field, then instead of using dom i can use "g_form.addDecoration" and "g_form.removeDecoration()" methods.



you can use g_form.getControl(), if you want to add background colour to a field.



g_form.getControl("caller_id").style.background-color = "red";



Thanks and regards


Swamy


Rohini Peraval1
Tera Contributor

Hi Sanjeev,


you can try the below code to retrieve the URL parameters, without using DOM.



var myParam = getParmVal('sysparm_preview');



function getParmVal(name){


  var searchKey=name;


  var query = window.location.search.substring(1);


  alert("111 "+query);


      var vars = query.split('&');


  alert("222 "+vars);


      for (var i = 0; i < vars.length; i++) {


              var pair = vars[i].split('=');


              if (decodeURIComponent(pair[0]) == searchKey) {


                      return decodeURIComponent(pair[1]);


              }


      }



Please Mark as Correct or Hit Like or Mark as helpful if Helps



Regards,


Rohini.P


Kalaiarasan Pus
Giga Sage

Sample function:



var gURL = new GlideURL();


gURL.setFromCurrent();


alert(gURL.getParam("sysparm_id"));



where sysparm_id is the parameter that needs to be read from URL.


reddys
Kilo Contributor

Is there a alternative way to hide UI macro on form without using DOM manipulation..



function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
          return;
    }
if (newValue =='') {
  var x = document.getElementById("callerLinkLocation").style.visibility="hidden";
}


var gr = new GlideRecord('new_call');
gr.query();
if (!gr.next()) {
  var y = document.getElementById("callerLinkLocation").style.visibility="hidden";
}
else {
  var z = document.getElementById("callerLinkLocation").style.visibility="visible";
}    
}