How to call System property in UI Action?

Ankita9
Tera Contributor

Hi,

Below is a Ui action where INC when promoted to Major Inc, vendor filed should auto-populate. it is working fine except the else part has some issue when Manulife Internal is already present in the vendor filed it should not add it twice. 

Can someone please suggest what can be done. Also, one of colleague said we should not hardcode SYS_ID and to use sys property instead. How to call it in this UI Action?

 

function promoteMIC() {
var arr = [];
var contact = "Manulife Internal";
var vendors = current.u_vendors;

if (global.JSUtil.nil(vendors))

{
current.u_vendors = contact;

} else {
arr = current.u_vendors.split(',');

var arrayUtil = new global.ArrayUtil();
if (!arrayUtil.contains(arr, "4affe5a4dbf89810075504c2ca961912")) {
arr.push(contact);
}
current.u_vendors = arr.join();
}
var mim = new sn_major_inc_mgmt.MajorIncidentTriggerRules(current);
mim.approveMIC();
action.setRedirectURL(current);
}

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ankita,

update as this

function promoteMIC() {
var arr = [];
var contact = "Manulife Internal";
var vendors = current.u_vendors;

if (global.JSUtil.nil(vendors))

{
current.u_vendors = contact;

} else {
arr = current.u_vendors.split(',');

var value = gs.getProperty("sn_major_inc_mgmt.promotemajorincident");

var arrayUtil = new global.ArrayUtil();
if (!arrayUtil.contains(arr, value)) {
arr.push(contact);
}
current.u_vendors = arr.join();
}
var mim = new sn_major_inc_mgmt.MajorIncidentTriggerRules(current);
mim.approveMIC();
action.setRedirectURL(current);
}

Regards
Ankur

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

View solution in original post

9 REPLIES 9

Pranesh072
Mega Sage
Mega Sage

define the property in sys_properties table

find_real_file.png

 

Use following code in UI action 

gs.getProperty("property_name"); //returns 4affe5a4dbf89810075504c2ca961912

Hi Parnesh,

 

Does this looks correct?

 

arr = current.u_vendors.split(',');

var arrayUtil = new global.ArrayUtil();
gs.getProperty("sn_major_inc_mgmt.promotemajorincident");

//if (!arrayUtil.contains(arr, "4affe5a4dbf89810075504c2ca961912"))

{
arr.push(contact);
}
current.u_vendors = arr.join();
}
var mim = new sn_major_inc_mgmt.MajorIncidentTriggerRules(current);
mim.approveMIC();
action.setRedirectURL(current);
}

 

 

try this 

arr = current.u_vendors.split(',');

var arrayUtil = new global.ArrayUtil();
var sysid = gs.getProperty("sn_major_inc_mgmt.promotemajorincident");

if (!arrayUtil.contains(arr, sysid))

{
arr.push(contact);
}
current.u_vendors = arr.join();
}
var mim = new sn_major_inc_mgmt.MajorIncidentTriggerRules(current);
mim.approveMIC();
action.setRedirectURL(current);
}

arr = current.u_vendors.split(',');

var arrayUtil = new global.ArrayUtil();

var val =gs.getProperty("sn_major_inc_mgmt.promotemajorincident"); //getting property value in variable

if (!arrayUtil.contains(arr, val)) //using this variable value to compare as per your logic

{
arr.push(contact);
}
current.u_vendors = arr.join();
}
var mim = new sn_major_inc_mgmt.MajorIncidentTriggerRules(current);
mim.approveMIC();
action.setRedirectURL(current);
}