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

I tried with below url :

https://dev72524.service-now.com/nav_to.do?uri=%2Fcom.glideapp.servicecatalog_cat_item_view.do%3Fv%3D1%26sysparm_id%3Da904ffda4fb133005e988020a310c71d&sysparm_channelid= qwergyedt5363&sysparm_channelname= Team

it is working fine but the value are comming undefined

find_real_file.png

Remove space in parameters.

I tried with that still values are not comming.

https://dev72524.service-now.com/nav_to.do?uri=%2Fcom.glideapp.servicecatalog_cat_item_view.do%3Fv%3D1%26sysparm_id%3Da904ffda4fb133005e988020a310c71d&sysparm_channelid=qwergyedt5363&sysparm_channelname=Team

function onLoad() {


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

var grURL= new GlideURL();

grURL.setFromCurrent();

var strUrl = grURL.getURL();


var Chid = grURL.getParam('sysparm_channelid');
var chname = grURL.getParam('sysparm_channelname');

g_form.setValue('u_channel_id', Chid);
g_form.setValue('u_channel_name', chname);


}

 

find_real_file.png

https://dev72524.service-now.com/com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=a904ffda4fb133005e988020a310c71d&sysparm_channelid=qwergyedt5363&sysparm_channelname=Team

Try this url

It Worked. Thank You so Much for the Help