how to pass the value from URL

RudhraKAM
Tera Guru

Hello, 

we have a requirement, can someone help me with the code. 

We have a catalog item, and there is a rich text HTML variable that is pointing to a record producer 

when the user clicks on that link the record producer will open in a new tab ,when the Record producer is submitted it should check if it is coming from that catalog item then it should set the Assignment group  to xyz on submit of that RC

 

Below is the link

https://servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script/

1 ACCEPTED SOLUTION

You can also consider below approach. 

  • First set the parameter in URL as tony suggested.
  • If you have not any variable over record producer form which is going to hold that URL parameter value then you can write below code in record producer "script" field to set that group into assignment group field.

eg:

 

var grp = gs.action.getGlideURI().getMap().get('sysparm_grp'); // sysparm_grp is url paramter
current.assignment_group.setDisplayValue(grp);

View solution in original post

3 REPLIES 3

Tony Chatfield1
Kilo Patron

Hi, as the link you supplied indicates you can pass a parameter to via a url using this basic format &sysparm_yourParmName

eg var myParm = '&sysparm_incident=' + current.sys_id;

var url = 'com.glideapp.servicecatalog_cat_item_view.do?&sysparm_id=sysidForYourRecordProducer' + myParm;

and then use an onload client script to extract the value.

I found forum posts that indicated the SNCGuru script needed to be updated due to SNC platform changes,
and this is the solution I use.
– I cannot recall where I found it, so can't give credit.

var testParm = getParmVal('sysparm_yourParmName’);

function getParmVal(name) {
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(location.href);

if (results == null) {
	return "";
	} else {
	return unescape(results[1]);
	}
}

Thanks, Tony for the reply, can you please help me with what should the rich text URL need to be?

I am a bit lost here, 

On the catalog item, we have this variable, what is the URL I need to use here?

find_real_file.png

 

As of now, This is the link record that is being used below is the link to the record producer which will create an inquiry. 

https://abcdev.service-now.com/com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=89ffc9fc1b11fc906ad8ec65604bcbd0

 

 

below is the catalog item URL

https://abcdev.service-now.com/nav_to.do?uri=%2Fcom.glideapp.servicecatalog_cat_item_view.do%3Fv%3D1%26sysparm_id%3D7ca1b97c1bd5fc906ad8ec65604bcbe5

 

when the link is clicked the record producer will be opened and after submitting the inquiry we need to check if that record producer is opened from the catalog item then set the assignement group to  "servicenow_admins"

You can also consider below approach. 

  • First set the parameter in URL as tony suggested.
  • If you have not any variable over record producer form which is going to hold that URL parameter value then you can write below code in record producer "script" field to set that group into assignment group field.

eg:

 

var grp = gs.action.getGlideURI().getMap().get('sysparm_grp'); // sysparm_grp is url paramter
current.assignment_group.setDisplayValue(grp);