on UI Action what the technique can replace a DOM manipulation technique 'gel()' , please see on my script

sudaporn
Giga Expert

find_real_file.png

Description  

Avoid Document Object Model (DOM) manipulation if possible.   It can cause a maintainability issue when browsers are updated.

Instead, use the GlideForm API or consider a different approach for the solution. In general, when using DOM manipulation methods, you have to reference an element in the DOM by id or using a CSS selector. When referencing out-of-box DOM elements, there is a risk that the element ID or placement within the DOM could change thus causing the code to stop working and/or generate errors. While we are not saying this should never be done, it needs to be done with forethought, caution, and a full understanding of the risk you are incurring. It is recommended to review these objects and reduce the use of DOM manipulation methods as much as possible.

How can i edit script

3 REPLIES 3

marcguy
ServiceNow Employee
ServiceNow Employee

What value are you trying to get from the form? if it's the sys_id of the record then you can use g_form.getUniqueValue()



if it's something else, there is also a function called g_form.getControl() which might help as well.



http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#getControl


Can i replace   line 4?



function u_print_contract() {


  var features = "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=yes,location=no";


  var href = [];


  href.push('sysparm_id=' + gel('sys_uniqueValue').value);




  win = window.open("/u_print_contract.do?sysparm_stack=no&" + href.join("&"), "Printer_friendly_format", features);


  win.focus();


  return false;


}


marcguy
ServiceNow Employee
ServiceNow Employee

href.push('sysparm_id=' + g_form.getUniqueValue());



if it is the sys_id of the record that you are trying to put into the sysparm_id value.