- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2025 10:24 AM - edited ‎06-26-2025 10:26 AM
Hi All,
I request you kindly help me on below issue.
we are trying to handle the error from ECC Queue PayLoad
var gr = new GlideRecord("ecc_queue");
gr.addQuery('sys_id', 'record sysID');
gr.query();
if(gr.next()){
var payloadxml= gr.payload.toString();
var objXML = new global.XMLDocument(payloadxml);
var xmloutput = objXML.getNodeText('//output').trim();
if(JSUtil.notNil(xmloutput)){
var result;
result=JSON.parse(xmloutput);
gs.info(" Result is : "+result.errors);// OUTPUT : [object object]
}
}
gs.info("Result has Length : "+result.errors.length);//OUTPUT: 1
gs.info("Result has Length : "+Object.keys(result.errors).length);//OUTPUT: 1
gs.info("Result has Length : "+Object.keys(result.errors).length>0);//OUTPUT: FALSE
it has to return TRUE, why it is returning as FALSE ?
Please help me on this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2025 09:12 PM
Hi @Supriya25
Correct format for using it inside an if condition:
if (!!result.errors && (Object.keys(result.errors).length > 0)) {
// Your logic here
}
Please accept answer and mark this as helpful if this answers your question.
Best Regards
Nitish Saini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2025 10:41 AM
Hi Supriya,
Use parentheses to make sure the logical comparison happens before the concatenation:
gs.info("Result has Length : " + (Object.keys(result.errors).length > 0));
OR
You can try this as well:-
var hasErrors = Object.keys(result.errors).length > 0;
gs.info("Result has errors: " + hasErrors);
Please mark this as helpful and accept answer if this answers your question.
Best Regards
Nitish Saini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2025 11:14 AM - edited ‎06-26-2025 11:16 AM
Hi @Nitish Saini
Object.keys(result.errors).length > 0 I would like to use in IF-CONDITTION
so which format I have to use
if( !!result.errors && Object.keys(result.errors).length > 0 )
Or
if( !!result.errors && (Object.keys(result.errors).length > 0) )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2025 09:12 PM
Hi @Supriya25
Correct format for using it inside an if condition:
if (!!result.errors && (Object.keys(result.errors).length > 0)) {
// Your logic here
}
Please accept answer and mark this as helpful if this answers your question.
Best Regards
Nitish Saini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2025 10:28 AM
when we are considering with other conditions also we took (Object.keys(result.errors).length > 0) in separate ().
But how about if I want to check only Object.keys ?
if( Object.keys(result.errors).length > 0 )
Or
if((Object.keys(result.errors).length > 0) )