Populate reference field using UI action

Virendra Dwived
Tera Expert

Hi Everyone, 

I have requirement to populate reference field using UI action. 

Ui Action:

var mName = g_form.getValue('instruct_model_name');
var mUrl = g_form.getValue('instruct_model_url');
var nDesc = g_form.getValue('model_description');
var ex_id = g_form.getValue('experience_id'); // string field present on table 1

 

var link = '<a href= ' + mUrl + ' target=_blank>Click here to launch</a>';

g_navigation.open("/kb_knowledge?sys_id=-1&sysparm_query=short_description= " + mName +
"^x_care3_carear_cus_important_id =" + ex_id + // [ x_care3_carear_cus_important_id is reference field present on table 2]
"^text =" + '<h1> <strong> ' + mName + ' </strong></h1> ' +
'<br/>' + '<h2>' + nDesc + '</h2> ' +
'<br/>' + '<h2>' + link + '</h2> ' , "_blank");


Thanks 

cc: @ankurt @Ankur Bawiskar 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Virendra Dwived 

update as this

var mName = g_form.getValue('instruct_model_name');
var mUrl = g_form.getValue('instruct_model_url');
var nDesc = g_form.getValue('model_description');
var ex_id = g_form.getValue('experience_id'); // string field present on table 1

// then query and get sysId

var rec = new GlideRecord("table"); // give here the table which is referred by x_care3_carear_cus_important_id field
rec.addQuery("u_name", ex_id); // give here the field name which holds data which you get in experience_id field
rec.query();
rec.next();

var link = '<a href= ' + mUrl + ' target=_blank>Click here to launch</a>';

g_navigation.open("/kb_knowledge?sys_id=-1&sysparm_query=short_description= " + mName +
"^x_care3_carear_cus_important_id =" + rec.getUniqueValue() + // [ x_care3_carear_cus_important_id is reference field present on table 2]
"^text =" + '<h1> <strong> ' + mName + ' </strong></h1> ' +
'<br/>' + '<h2>' + nDesc + '</h2> ' +
'<br/>' + '<h2>' + link + '</h2> ' , "_blank");

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

View solution in original post

6 REPLIES 6

Virendra Dwived
Tera Expert

Hi @Ankur Bawiskar 

 

Can you please guide me with this task?

Ankur Bawiskar
Tera Patron
Tera Patron

@Virendra Dwived 

update as this

var mName = g_form.getValue('instruct_model_name');
var mUrl = g_form.getValue('instruct_model_url');
var nDesc = g_form.getValue('model_description');
var ex_id = g_form.getValue('experience_id'); // string field present on table 1

// then query and get sysId

var rec = new GlideRecord("table"); // give here the table which is referred by x_care3_carear_cus_important_id field
rec.addQuery("u_name", ex_id); // give here the field name which holds data which you get in experience_id field
rec.query();
rec.next();

var link = '<a href= ' + mUrl + ' target=_blank>Click here to launch</a>';

g_navigation.open("/kb_knowledge?sys_id=-1&sysparm_query=short_description= " + mName +
"^x_care3_carear_cus_important_id =" + rec.getUniqueValue() + // [ x_care3_carear_cus_important_id is reference field present on table 2]
"^text =" + '<h1> <strong> ' + mName + ' </strong></h1> ' +
'<br/>' + '<h2>' + nDesc + '</h2> ' +
'<br/>' + '<h2>' + link + '</h2> ' , "_blank");

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

Hi @Ankur Bawiskar 

 

What do you mean by u_name in line rec.addQuery("u_name", ex_id); . experience_id is field which stores value on table 1.

Hi,

experience_id stores some string.

You need to decide against which field of the table you need to query to get the record

So that field you have to use in place of u_name

I just gave an example

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