How do you link to a record producer and pass some of the parameters in the url?

mahudg2
Kilo Expert

On a front page I want to be able to have several links to one record producer and pass some of the data in the url so some of the fields can be pre-filled. I've done this with incidents before with the sysparm_query by adding sysparm_query=priority=1^incident_state=3 to the url

 

But I can't seem to get it to work with record producers. Keep in mind that I'm using custom variables.

 

Is this possible?

1 ACCEPTED SOLUTION

andrew_venables
ServiceNow Employee
ServiceNow Employee

Use an onLoad Catalog Client Script like the below:



function onLoad() {


  var cmdb_ci = getParmVal('sysparm_cmdb_ci');


  if (cmdb_ci) {


        g_form.setValue('cmdb_ci', cmdb_ci);


  }


}




function getParmVal(name) {


  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");


  var regexS = "[\\?&]"+name+"=([^&#]*)";


  var regex = new RegExp(regexS);


  var results = regex.exec( window.location.href );


  if(results == null){


        return "";


  }


  else{


        return unescape(results[1]);


  }


}





and you can pass in like:



var params = 'sysparm_cmdb_ci=' + current.sys_id;


var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=c60ea0806f159500d9c316ff8d3ee400';


action.setRedirectURL(url + '&' + params);


View solution in original post

9 REPLIES 9

Bhavesh Jain1
Giga Guru

You can write onLoad script for each record producer.



Use this syntax to get the previous URL : alert(document.referrer);


Based on this URL, you will understand the variables you need to set.Let me know if you have queries.


I haven't been able to get the alert to trigger. I also attempted putting this in an onLoad event.


never mind I realize now that I need to put this in the catalog script. Thank you!


andrew_venables
ServiceNow Employee
ServiceNow Employee

Use an onLoad Catalog Client Script like the below:



function onLoad() {


  var cmdb_ci = getParmVal('sysparm_cmdb_ci');


  if (cmdb_ci) {


        g_form.setValue('cmdb_ci', cmdb_ci);


  }


}




function getParmVal(name) {


  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");


  var regexS = "[\\?&]"+name+"=([^&#]*)";


  var regex = new RegExp(regexS);


  var results = regex.exec( window.location.href );


  if(results == null){


        return "";


  }


  else{


        return unescape(results[1]);


  }


}





and you can pass in like:



var params = 'sysparm_cmdb_ci=' + current.sys_id;


var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=c60ea0806f159500d9c316ff8d3ee400';


action.setRedirectURL(url + '&' + params);