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

Hi,

update as this

Changes in bold

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

Viraj Hudlikar
Tera Sage
Tera Sage

Hi @Ankita 

Have a look on this LINK which will help you to understand how to create and access property.

First create a property in sys_properties.list and then use below code in 

Accessing a property in server-side script (Business Rules, UI Actions, UI Pages, etc.)

var propertyValue = gs.getProperty('your.property.name.here');

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

Thanks & Regards,
Viraj Hudlikar.

Abdul_Rahiman
Tera Guru

Hi Ankita,

 

 Below is the Syntax to call System property.

var  val = gs.getProperty('name of the system property');

 

Regards,

Abdul Rahiman

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

Hi Ankur,

 

Thanks!! After promoting inc to Major the vendor watchlist filed is not supposed to get locked but it is getting locked when i click on it. Can you please help me understand why is it happening so?