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

Hi @Ankur Bawiskar 

Let me explain my requirement:

1. experience_Id (string ) is in custom table.

2. x_care3_carear_cus_important_id (reference field) is in kb_knowledge table. And this field is referenced to custom table. 

So, when I click on Ui action present in custom table it should open knowledge article form pre populated x_care3_carear_cus_important_id ( Reference field) based on experience_Id on custom table.

 

Thanks and regards 

Virendra

Hi,

what are the tables in point 1 and point 2?

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