Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help Needed with Condition Script in 'Look Up Records' Action

Ankit Balapure
Tera Contributor

Hi,

 

I’m trying to write a condition in the Condition Script snippet of the ‘Look Up Records’ action in Flow Designer, but I’m unsure how to write it correctly and return the expected results.

 

Requirement:

The condition script should return records where:

  • u_employee_type is 'Consultant'

  • AND u_user_principal_name does not start with 'p000'

 

Please refer the following screenshots.

 

Used the Look Up Records action.

 

AnkitBalapure_0-1748697417502.png

 

AnkitBalapure_1-1748697743819.png

 

 

However, it is returning all 20 records from the target table, even though only 2 records meet the above criteria in the backend.

 

AnkitBalapure_2-1748697848085.png

Only the 2 matching records should be returned by the lookup action.

 

Kindly help me with how to write the correct condition script to achieve this?

 

Thanks,

Ankit B

1 REPLY 1

Ankit Balapure
Tera Contributor

Hi Everyone,

I wanted to share that I've found a workaround for the issue I mentioned earlier.

I tested the solution by using the following code in the Condition Script snippet of flow designer, and it worked as expected:

The following script checking the  

  • u_employee_type is 'Consultant'

  • AND u_user_principal_name does not start with 'p000'

And it is returning the correct record from the table.

var listQury = 'u_employee_type=consultant^u_user_principal_nameIN';
var listVals = '';
var list = new GlideRecord("table_name");
list.addQuery('u_employee_type','Consultant');
list.addQuery('u_user_principal_name', 'NOT LIKE', 'y%');
list.query();
while (list.next()) {
	
		listVals = listVals + list.u_user_principal_name + ',';
	
} 
return listQury+listVals;

 

Output: 

AnkitBalapure_0-1748700936698.png

 

AnkitBalapure_1-1748701053659.png

 

Thanks,

Ankit B