The CreatorCon Call for Content is officially open! Get started here.

UI Action to auto populate reference field

Ben F_
Giga Contributor

Hello All, 

I am attempting to click a related link, on the incident form, and have it carry values over to the new custom form. I am using a UI action and testing with the number field. 

Coming from: Incident Table (incident) 

Going to: Custom Table (u_dispatch_email_template) 

 

Here is my code currently: 

var num = current.getValue("number");

var url = 'https://service-now.com/nav_to.do?uri=%2Fu_dispatch_email_template.do?v=1&sysparm=u_incident_number='+num;

gs.setRedirect(url);

 

It is going to the right place when clicked but not populating the number field. 

 

Thanks, 

Ben 

 

1 ACCEPTED SOLUTION

Hi Ben,

here is the corrected code

you are sending the value incorrectly send the parameter as sysparm_u_incident_number

if the field on new table is string then use this

var num = current.getValue("number"); // use if the field on new table is string

var url = 'https://service-now.com/nav_to.do?uri=%2Fu_dispatch_email_template.do?v=1&sysparm_u_incident_number=' + num;

gs.setRedirect(url);

if the field on new table is reference to incident table then use this

var sysId = current.getValue('sys_id'); // use if field on new table is reference to incident table accordingly set the value in the url

var url = 'https://service-now.com/nav_to.do?uri=%2Fu_dispatch_email_template.do?v=1&sysparm_u_incident_number=' + sysId;

gs.setRedirect(url);

on load on the table u_dispatch_email_template should be 

function onLoad(){

var gURL = new GlideURL();
gURL.setFromCurrent();
var number = gURL.getParam("sysparm_u_incident_number");

g_form.setValue('fieldName',number);

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Elijah Aromola
Mega Sage

Try doing just current.number.

SanjivMeher
Kilo Patron
Kilo Patron

You code should be

 

var num = current.getValue("number");

var url = '/nav_to.do?uri=%2Fu_dispatch_email_template.do?sys_id=-1&sysparm_query=u_incident_number='+num;

gs.setRedirect(url);


Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv, 

 

I used your code. When I added a: 

gs.addInfoMessage('Current Incident Number is '+ num); 

 

It displays the correct incident number. However, it still is not populating the field on the new form.

 

Any ideas? 

Hi Ben,

here is the corrected code

you are sending the value incorrectly send the parameter as sysparm_u_incident_number

if the field on new table is string then use this

var num = current.getValue("number"); // use if the field on new table is string

var url = 'https://service-now.com/nav_to.do?uri=%2Fu_dispatch_email_template.do?v=1&sysparm_u_incident_number=' + num;

gs.setRedirect(url);

if the field on new table is reference to incident table then use this

var sysId = current.getValue('sys_id'); // use if field on new table is reference to incident table accordingly set the value in the url

var url = 'https://service-now.com/nav_to.do?uri=%2Fu_dispatch_email_template.do?v=1&sysparm_u_incident_number=' + sysId;

gs.setRedirect(url);

on load on the table u_dispatch_email_template should be 

function onLoad(){

var gURL = new GlideURL();
gURL.setFromCurrent();
var number = gURL.getParam("sysparm_u_incident_number");

g_form.setValue('fieldName',number);

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader