Counting open requests from a requester

dscov22
Tera Contributor

Hi,

 

I want to write a BR that counts previously opened requests from the same requester and doesn't allow them to open more requests if they already have 7 or more open.

 

Here's what I have

 

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

	var requester  = current.u_requester;
	var gr = new GlideRecord('u_chromatech_customer_queries');
	gr.addQuery('u_requester', requester);
	gr.query();
// 	gs.addInfoMessage(gr.getRowCount());
// 	gs.addInfoMessage(requester.getDisplayValue());
// 	gs.addInfoMessage(requester);

})(current, previous);

the info messages show that I am not getting a value for var requester, I've tried a few methods like getValue and getDisplayValue and cannot seem to populate the requester variable.

 

No matter what I try the info messages for requester are always blank

Thanks for your time

 

1 ACCEPTED SOLUTION

GTSNOW
Giga Guru

Hi,

 

I tried and it worked as follow.

I tried to create 5th record and I got the error. I have provided the code used. Please try yourself. 

 

GTSNOW_0-1693422529723.png

GTSNOW_1-1693422536630.png

 

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

	// Add your code here
	var count = 0;
	var grD = new GlideRecord('u_demo_table');
	grD.addQuery('u_requestor',current.u_requestor);
	grD.query();
	while(grD.next())
		{
			count = grD.getRowCount();
		}
	if (count >= 4 )
		{
			gs.addErrorMessage("Cannot creater more requests");
			current.setAbortAction(true);
		}

})(current, previous);

If you found my response helpful or relevant to your query, please consider clicking the "Helpful" button or giving it a "Like". This not only helps others identify useful replies but also encourages contributors like me to continue assisting the community. Thank you for your support!

 

 

View solution in original post

2 REPLIES 2

GTSNOW
Giga Guru

Hi,

 

I tried and it worked as follow.

I tried to create 5th record and I got the error. I have provided the code used. Please try yourself. 

 

GTSNOW_0-1693422529723.png

GTSNOW_1-1693422536630.png

 

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

	// Add your code here
	var count = 0;
	var grD = new GlideRecord('u_demo_table');
	grD.addQuery('u_requestor',current.u_requestor);
	grD.query();
	while(grD.next())
		{
			count = grD.getRowCount();
		}
	if (count >= 4 )
		{
			gs.addErrorMessage("Cannot creater more requests");
			current.setAbortAction(true);
		}

})(current, previous);

If you found my response helpful or relevant to your query, please consider clicking the "Helpful" button or giving it a "Like". This not only helps others identify useful replies but also encourages contributors like me to continue assisting the community. Thank you for your support!

 

 

dscov22
Tera Contributor

Thank you very much that works great