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

on Before Insert Business Rule problem

Alon Grod
Tera Expert

I have an on Before insert BR on the incident table that suppose to populate the assignment group field. Even though Im getting the log 'TRUE', the assignment group is not populated and instead Im getting an empty value inside the assignment group field. I checked and there is no BR that conflict with this BR. What am I doing wrong?

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var loc = current.location;

	var gr = new GlideRecord('cmn_location');
	gr.addEncodedQuery('sys_id='+loc+'^u_assignment_groupISNOTEMPTY');
	gr.query();
	if(gr.hasNext()){
		gs.log('TRUE');
		current.assignment_group = gr.u_assignment_group;
	}
	else{
		
	}

})(current, previous);
1 ACCEPTED SOLUTION

Prince Arora
Tera Sage

@Alon Grod ,

 

hasNext() either returns true or false while next() will actually iterate to the record.

 

try updating the code as:

gr.next()

 

 

View solution in original post

13 REPLIES 13

priyasunku
Kilo Sage

@Alon Grod 

 

Can you check  if it is returning any value on below field by keeping logs.

gr.u_assignment_group

 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

Ankur Bawiskar
Tera Patron
Tera Patron

@Alon Grod 

are you sure location table has u_assignment_group field and it has value in it?

Is that field "u_assignment_group" a reference to group table?

if yes then it should work fine.

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

@Ankur Bawiskar @priyasunku 

 

I added another log to see what am I getting for gr.u_assignment_group and Im getting undefined. This field exist in the cmn_location table and its a reference field to sys_user_group and it has value in it.

@Alon Grod 

 

can you try below code

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var loc = current.location;

	var gr = new GlideRecord('cmn_location');
	gr.addEncodedQuery('sys_id='+loc+'^u_assignment_groupISNOTEMPTY');
	gr.query();
	if(gr.next()){
		gs.log('TRUE');
		current.assignment_group = gr.u_assignment_group;
	}
	

})(current, previous);

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful