Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to check 0/null in addQuery for ''Currency' type field?

Pranshu3
Tera Expert

I have a currency type field in pm_project table. On GlideRecord of this table, I would like to check null/0 value on the currency field.

Could you please help?

1 ACCEPTED SOLUTION

Pranshu3
Tera Expert

Hi,

Thanks for the suggestions, I was looking for value check in addQuery of GlideRecord. Below simple code worked fine:

var projectGR = new GlideRecord('pm_project');
projectGR.addQuery('cost','!=','0'); //check Total Planned Cost
projectGR.query();

Here, cost(Total planned cost) is the Currency field.

View solution in original post

5 REPLIES 5

Mark Roethof
Tera Patron

Hi there,

Can you simulate that through a list (I would think Yes)? If so, this might help:

Utilizing the breadcrumb on lists to generate your query

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

hvrdhn88
Giga Patron

try with  below code. 

 

var gr = new GlideRecord('pm_project');

gr.query();

while(gr.next()){

if(gr.<currency field name> == null || gr.<currency field name> == 'USD;0'){

gs.print(gr.number);

}

}

Ajay_Chavan
Kilo Sage

Hi there,

 

Value stored in currency field is as below:

 

find_real_file.png

 

so you will have to write code considering this value.

for example:

if(gr.<filedname> == null || gr.<filedname> == 'USD;0.00')

 

 

If this resolves your query, please mark my comments as correct  and helpful  .

Regards,

Ajay Chavan

My Community Articles

LinkedIn

 

Glad I could help! If this solved your issue, please mark it as ✅ Helpful and ✅ Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

DrewW
Mega Sage

Last I checked, which was today, Currency fields always return zero even when they are null/empty so you can just do

if(gr.getValue("field") == 0)

and that will take care of having to worry about the currency used.