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

Need Scripting Help on Condition to Run Biz Rule

mrcorbeaux
Kilo Guru

Hello Developers,

There is an OOB Business Rule that is part of the Procurement Plug-In called: Can request be sourced.
It runs on the sc_request table to make an REQ sourceable.
It looks at the variable 'cat_item' on the sc_req_item table to see if it has a model. If so, it sets the 'sourceable' variable on the REQ to True.

Is there a way to have this Biz Rule run only if the cat_item sys_ID is NOT 'c344cd6487ee051015aafe29cebb3590' ? That sys_id has and needs a model but I don't want the rule to run on that one.
I cannot use the When To Run condition because 'cat_item' is on the sc_req_item table. 

Ultimately I want to use that OOB Biz Rule to not run on that sys_id and create a similar one with additional code that will run ONLY if cat_item sys_ID IS c344cd6487ee051015aafe29cebb3590.

 

Thank you.

 

sourceable(current);

function sourceable(record) {
  var C_STOCK_ORDER_CAT_SYS_ID = '4109aa5fdb22001015a8ffefbf961984';
  var gr = new GlideRecord("sc_req_item");
  gr.addQuery("request", record.sys_id);
  //A OR (B AND C) not supported
	//Hence going for (A OR B) AND (A OR C)
	var qc = gr.addNotNullQuery("cat_item.model");
	if (GlidePluginManager.isActive('com.sn_hamp')) {
		qc.addOrCondition("cat_item.sys_id", C_STOCK_ORDER_CAT_SYS_ID);
		qc.addOrCondition('variables.dbccd3f2b7621010189e22b5de11a90e', '!=', '');//expecting this catalog item only if HAMP is active, hence not checking if HAMP active or not
		// need to enhance code
		var qc1 = gr.addNotNullQuery("cat_item.model");
		qc1.addOrCondition("variables.6189629fdb22001015a8ffefbf96197f", "!=", "");//Checking if model variable is not null
		qc1.addOrCondition('variables.dbccd3f2b7621010189e22b5de11a90e', '!=', '');
	}
	gr.setLimit(1);
	gr.query();
	if (gr.hasNext()) {
    // DEF0275710 - Re-querying and updating the request record to avoid extra record in audit
		var request = new GlideRecord("sc_request");
		request.addQuery("sys_id", record.sys_id);
		request.query();
		if(request.next()){
			request.sourceable = true;
			request.update();
		}
	}
}

 

 

1 ACCEPTED SOLUTION

AshishKM
Kilo Patron
Kilo Patron

Hi @mrcorbeaux ,

You can update the BR with addQuery condition and filter out  the said cat item for further processing.

var gr = new GlideRecord("sc_req_item");
  gr.addQuery("request", record.sys_id);
  gr.addQuery('cat_item!=c344cd6487ee051015aafe29cebb3590');

-Thanks,

AshishKMishra

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

6 REPLIES 6

Shubham Singh
Mega Guru

Hi @mrcorbeaux 

 

Try this:

 

 

 

var ritm = new GlideRecord("sc_req_item");
ritm.addQuery("request", current.sys_id);
ritm.query();
if(ritm.next()){
     if(ritm.cat_item != 'c344cd6487ee051015aafe29cebb3590'){
           sourceable(current);
     }
}


function sourceable(record) {
  var C_STOCK_ORDER_CAT_SYS_ID = '4109aa5fdb22001015a8ffefbf961984';
  var gr = new GlideRecord("sc_req_item");
  gr.addQuery("request", record.sys_id);
  //A OR (B AND C) not supported
	//Hence going for (A OR B) AND (A OR C)
	var qc = gr.addNotNullQuery("cat_item.model");
	if (GlidePluginManager.isActive('com.sn_hamp')) {
		qc.addOrCondition("cat_item.sys_id", C_STOCK_ORDER_CAT_SYS_ID);
		qc.addOrCondition('variables.dbccd3f2b7621010189e22b5de11a90e', '!=', '');//expecting this catalog item only if HAMP is active, hence not checking if HAMP active or not
		// need to enhance code
		var qc1 = gr.addNotNullQuery("cat_item.model");
		qc1.addOrCondition("variables.6189629fdb22001015a8ffefbf96197f", "!=", "");//Checking if model variable is not null
		qc1.addOrCondition('variables.dbccd3f2b7621010189e22b5de11a90e', '!=', '');
	}
	gr.setLimit(1);
	gr.query();
	if (gr.hasNext()) {
    // DEF0275710 - Re-querying and updating the request record to avoid extra record in audit
		var request = new GlideRecord("sc_request");
		request.addQuery("sys_id", record.sys_id);
		request.query();
		if(request.next()){
			request.sourceable = true;
			request.update();
		}
	}
}

 

 

 

 

Thanks!

 

Please mark this response as correct and helpful ✔️👍

Hello Shubham,

That actually still launched the biz rule when that sys_id was ordered. But thanks for responding.

@Shubham Singh , your approach is good but the gap is when "sourceable" called then it's including that cat_item. 

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

AshishKM
Kilo Patron
Kilo Patron

Hi @mrcorbeaux ,

You can update the BR with addQuery condition and filter out  the said cat item for further processing.

var gr = new GlideRecord("sc_req_item");
  gr.addQuery("request", record.sys_id);
  gr.addQuery('cat_item!=c344cd6487ee051015aafe29cebb3590');

-Thanks,

AshishKMishra

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution