- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2025 02:17 AM
We have a decimal field which can either contain values from 0-10 or it can be empty.
let impactRiskScoreExists = !gr.u_impact_risk_score.nil();
if(impactRiskScoreExists){
// Further process
}
The issue is that sometimes in case the value is 0, the value of impactRiskScoreExists is either true or false. Is there any other way to validate for a decimal type field value?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2025 02:24 AM
try this
var impactRiskScore = gr.u_impact_risk_score;
var impactRiskScoreExists = impactRiskScore !== null && impactRiskScore !== undefined;
if (impactRiskScoreExists) {
// Further process
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2025 02:24 AM
try this
var impactRiskScore = gr.u_impact_risk_score;
var impactRiskScoreExists = impactRiskScore !== null && impactRiskScore !== undefined;
if (impactRiskScoreExists) {
// Further process
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2025 02:37 AM
If your concern is that the field can be within a specific range (0-10), you could also ensure the value falls within that range by using a condition like this:
let impactRiskScore = gr.u_impact_risk_score;
let impactRiskScoreExists = impactRiskScore !== null && impactRiskScore !== undefined && impactRiskScore >= 0 && impactRiskScore <= 10;
if (impactRiskScoreExists) {
// Further process
}
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2025 03:21 AM
Hello @Nishant Kumar5, If you'd like to just validate whether this field is null or not, then you can try below:
var impactRiskScoreValue = gr.getValue('u_impact_risk_score');
var impactRiskScoreExists = impactRiskScoreValue != null && impactRiskScoreValue != undefined;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2025 03:42 AM
super easy, just use gs.nil method.
It will return true only the field is empty.
var gr = new GlideRecord('incident');
if (gr.get('57af7aec73d423002728660c4cf6a71c')) {
if (gs.nil(gr.u_score)) {
// only run no value on this field
gs.print('score is null');
} else {
gs.print("score: " + gr.u_score);
}
}