Display Business Rule is not working

User205031
Tera Contributor

Hello All,

 

We have a requirement in HAM task. There is a choice field 'A' in 'sys_user' table. So if the requested for's 'A' field is 'Yes' then in the HAM task there is a choice field which will show an extra choice option.

 

I have created a Display Business rule and client script to show the extra choice option, but it is not working. It is always showing the scratchpad variable as false even if 'A' field for Requested for  is 'Yes'

 

Display business rule:

Running on HAM task table:

function executeRule(current, previous /*null when async*/) {
 
// Add your code here
 
var flag = 'false';
 
var a = new GlideRecord('sn_hamp_asset_reclaim_task');
a.addQuery('asset_reclaim_line', current.asset_reclaim_line);
a.addQuery('task_name=e');
a.query();
if(a.next()){
if(a.requested_for.A == 'Yes'){
flag = 'true';
 
}
}
 
g_scratchpad.isValue = flag;
 
})(current, previous);
 
Client Script:
Running on HAM Task table
function onLoad() {
//Type appropriate comment here, and begin script below

var taskName = g_form.getValue('task_name');
var b = g_scratchpad.isValue;
alert(b);

if(taskName == 'e' && b == 'true'){
g_form.addOption('evaluation_status', 'r', 'R', 4);
}
else {
g_form.removeOption('evaluation_status', 'r', 'R', 4);
}

}
10 REPLIES 10

Peter Bodelier
Giga Sage

Hi @User205031,

 

Please use below script in BR to trace where it is going wrong:

function executeRule(current, previous /*null when async*/) {
	var flag = 'false';
	var a = new GlideRecord('sn_hamp_asset_reclaim_task');
	a.addQuery('asset_reclaim_line', current.getValue('asset_reclaim_line'));
	a.addEncodedQuery('task_name=e');
	a.query();
	gs.info('Debug BR - Encoded Query: ' + a.getEncodedQuery());
	if (a.next()) {
		gs.info('Debug BR - has next: ' + a.getUniqueValue());
		var requestedFor = a.requested_for.getRefRecord();
		if (requestedFor.isValidRecord()){
			gs.info('Debug BR - Requested For: ' + requestedFor.getUniqueValue());
			gs.info('Debug BR - Requested For A: ' + requestedFor.getValue('a'));
			if (requestedFor.a == 'Yes') {
				gs.info('Debug BR - Requested For A is Yes');
				flag = 'true';
			}
			else{
				gs.info('Debug BR - Requested For A is not Yes');
			}
		}
		else{
			gs.info('Debug BR - Requested For not a valid record');
		}
	}
	else{
		gs.info('Debug BR - has no next');
	}
	g_scratchpad.isValue = flag;
}

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.