IF statement always returning true.

Venjamin
Tera Contributor

So, I have a fairly basic script, that should, in theory, be giving me one specific answer. I'm looking for it to find "Snowflake - HCDA PII Prod" and ensure that the PII Approval checkbox is true. I have tried removing the second feature - the name should be enough. 

 

For some reason, though, it always seems to be returning yes. I feel like I am overlooking something really basic, and I'm going to feel incredibly goofy. I tried with double quotes and single, I tried changing it up to search for the sys_id instead of the name. I tried swapping to an encoded query. It's just always delivering 'yes.' Please someone take a look and put me out of my misery? 

 

answer = ifScript();

function ifScript() {

var catvar = new GlideRecord("u_catalog_item_variables_list");
//catvar.get(obj.mrvs_al);
catvar.addQuery('u_name', 'Snowflake - HCDA PII Prod');
catvar.addQuery('u_needs_pii_approval', true);
catvar.query();
		gs.log('VVVVVV info reference- ' + current.variables.sar_system);
		gs.log('VVVVVV info NPA- ' + catvar.u_needs_pii_approval);
if (catvar.next()) {
return 'yes';
}
1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hi @Venjamin 

If it's returning as yes that means record with that query is present in that table.

Can you check if record is present in the table.

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

6 REPLIES 6

Vishal Birajdar
Giga Sage

Hi @Venjamin 

If it's returning as yes that means record with that query is present in that table.

Can you check if record is present in the table.

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Yes, the record is present. Oh man, I think I see what you mean. I forgot to make an actual comparative clause. 

It should be checking catvar against the current.variables.sar_system. 

I just went too deep. I just need to have it check if current.variables.sar_system = Snowflake - HCDA PII Prod then yes, else no. I knew this was going to be something silly.