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.

How to get the field value for Record producer from URL and redirecting the user to a page after submitting the record

Priyanshu
Giga Expert

Hello all,

I have created a record producer with three field Channel Name (Single line text), Channel ID (Single line text) and User name (reference type referring user table). Now my concern is how to get the Value for all these field from url and on submit how to redirect the user to different page.

Requirement is:

I need to give a URL(ServiceNow URL) to our client, in that URL they will be passing the two value Channel name and channel id and once end user will hit that user he will be asked to login incase there is no session and after login, i need to capture his user id. now i have all the three fields value i need to create a record in a table without any manual interruption from the end user. once the record is created i need to redirect the end user to a page where i will be showing some success message that your record has been created.

To achieve the requirement i have created a record producer with three field now how to get the value from url and what URL i should be sharing with the client so that they can pass the value.

NOTE: I can not user Rest API here as the response of the API will be either in XML or JSON format and i need to redirect end user to a page once record is created.

 

Please help me out here with scripting and best practice.

1 ACCEPTED SOLUTION

vandna
Tera Guru

Hi,

 

You can use GlideUrl function to get the current url parameter and you can redirect Record producer using 'producer.redirect="home.do";' line at the end of the producer script.

 

GlideUrl example.

 

var grURL= new GlideURL();

//Set the current URL

grURL.setFromCurrent();


var strUrl = grURL.getURL();

grURL.getParam(<url parameter name>);

View solution in original post

19 REPLIES 19

This is something that i did in catalog client script but it is not working and which URL i will be giving to client to pass the value for channel name and channel id and every time when this URL is hit i want to create a record.

 

Can you help me a bit more here to close the case.

 

function onLoad() {

var user = g_user.userID;
g_form.setValue('u_user_id', user);

var grURL= new GlideURL("https://dev72524.service-now.com/nav_to.do?uri=sc_cat_item.do?sys_id=a904ffda4fb133005e988020a310c71d + '&sysparm_channelid= qwergyedt5363' + '&sysparm_channelname= Team'");



grURL.setFromCurrent();

var strUrl = grURL.getURL();


var Chid = grURL.getParam('sysparm_channelid');
g_form.setValue('u_channel_id', Chid);

var chname = grURL.getParam('sysparm_channelname');
g_form.setValue('u_channel_name', chname);

 

}

Don't include URL in GlideURL function, script will be same as i have given you. Just need to add  g_form.setValue('u_channel_name', chname); at the end of script. you can give below URL to end user.

 

https://dev72524.service-now.com/nav_to.do?uri=sc_cat_item.do?sys_id=a904ffda4fb133005e988020a310c71d &sysparm_channelid= qwergyedt5363&sysparm_channelname= Team

 

when i am hitting the above URL i am getting redirected to Record producer page. below is the snapshot.

 

find_real_file.png

It worked issue was with URL. Thanks alot.

vandna
Tera Guru

Click on Preview Item link a popup will open, then Copy URL. Append the URL with the &sysparm_channelid=qwergyedt5363&sysparm_channelname=Team.