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

Query list type field within business rule?

Edwin Fuller
Tera Guru

I need to create a new record if the field "impacted_department" does NOT contain the assignment group "PI HPS Delivery" which sys_id is 5ebb037bdb4ff200a21a77478c9619fb. The "impacted_department" field is a list type field that references the group table. I believe line 2 below is incorrect. How someone show me how can I query a list type field?

 

 

if(current.product.business_unit == 'PI'){ // Create Assessment for PI HPS Delivery
if(current.impacted_departmentNOT LIKE5ebb037bdb4ff200a21a77478c9619fb){
var gr1 = new GlideRecord('x_hemas_connectus2_task');
gr1.initialize();
gr1.parent = current.sys_id;
gr1.requested_by = gs.getUserID();
gr1.requested_for = current.requested_for;
gr1.short_description = "Change Request - Impact Assessment";
gr1.u_hms_contract = current.primary_contract;
gr1.product = current.product;
gr1.opened_by = gs.getUserID();
gr1.assignment_group = "5ebb037bdb4ff200a21a77478c9619fb";
gr1.task_type = 'Change Request - Impact Assessment';
gr1.client_action = current.client_responsibilites;
gr1.description = current.shortdescription;
gr1.requested_delivery_date = current.requested_delivery_date;
gr1.additional_contracts = current.contract_impacted;
gr1.insert();

}
}

1 ACCEPTED SOLUTION

Syvo
Giga Guru

Hi Edwin,

I think your mixing GlideRecord encoded queries and simple Javascript conditions. Line 2 should be more like this:

if(current.getValue("impacted_department").toString().indexOf("5ebb037bdb4ff200a21a77478c9619fb") > -1){

But using a sys_id in your code is a bad practice. Instead, create a system property like "impacted_department.exception" and use it like this:

var impactedDept = gs.getProperty("impacted_department.exception", false);
if (!impactedDept) {
   gs.addErrorMessage("impacted_department.exception is not set!");
} else {
   if(current.getValue("impacted_department").toString().indexOf(impactedDept) > -1){
   [...]

HTH
Sylvain

 

View solution in original post

2 REPLIES 2

Syvo
Giga Guru

Hi Edwin,

I think your mixing GlideRecord encoded queries and simple Javascript conditions. Line 2 should be more like this:

if(current.getValue("impacted_department").toString().indexOf("5ebb037bdb4ff200a21a77478c9619fb") > -1){

But using a sys_id in your code is a bad practice. Instead, create a system property like "impacted_department.exception" and use it like this:

var impactedDept = gs.getProperty("impacted_department.exception", false);
if (!impactedDept) {
   gs.addErrorMessage("impacted_department.exception is not set!");
} else {
   if(current.getValue("impacted_department").toString().indexOf(impactedDept) > -1){
   [...]

HTH
Sylvain

 

Edwin Fuller
Tera Guru

Thanks Sylvain,