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.

On load client script for applying Change template not working through Related lists

Deepansh Jain
Kilo Contributor

 

Hello ,

I have created a template and  have applied an 'on load' client script, which when a new change form is loaded the template is applied ,

My 2 additional requirements are 

1. CRs created from any related list (ex: parent RITM), template is not getting applied

2. Copy change functionality not working 

 

Currently using this Client Script-

function onLoad() {
if(g_form.getValue('type') == 'normal' || g_form.getValue('type') == 'emergency'){
if(g_form.getValue('number') == ''){
var template = g_scratchpad.Mytemplate;
//Apply the selected template
applyTemplate(template);
}}}

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

Please try below.

function onLoad() {

var sysId = getParmVal('sys_id');
var tiny = getParmVal('sysparm_tiny');
gs.addInfoMessage(tiny);

if(g_form.getValue('type') == 'normal' || g_form.getValue('type') == 'emergency'){
 if(g_form.isNewRecord() && (sysId == '-1' || tiny != '')){ // check whether the record is new and not creating from copy chang
  var template = g_scratchpad.Mytemplate;
  //Apply the selected template
   applyTemplate(template);
 }
}
}

// get and parse URL paramters
function getParmVal(name) {
 alert(name);
	var url = document.URL.parseQuery();
	alert(url);
	if (url[name]) {
		alert(url[name]);
		return decodeURI(url[name]);
	} else {
		return '';

	}
}
Regards,
Muhammad

View solution in original post

6 REPLIES 6

MrMuhammad
Giga Sage

Please try below.

function onLoad() {

var sysId = getParmVal('sys_id');
var tiny = getParmVal('sysparm_tiny');
gs.addInfoMessage(tiny);

if(g_form.getValue('type') == 'normal' || g_form.getValue('type') == 'emergency'){
 if(g_form.isNewRecord() && (sysId == '-1' || tiny != '')){ // check whether the record is new and not creating from copy chang
  var template = g_scratchpad.Mytemplate;
  //Apply the selected template
   applyTemplate(template);
 }
}
}

// get and parse URL paramters
function getParmVal(name) {
 alert(name);
	var url = document.URL.parseQuery();
	alert(url);
	if (url[name]) {
		alert(url[name]);
		return decodeURI(url[name]);
	} else {
		return '';

	}
}
Regards,
Muhammad

Thanks for the help ,it worked

Happy to be of help 🙂 Have a great weekend & stay safe!

Regards,
Muhammad