- 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-27-2025 12:40 PM - edited ‎06-27-2025 12:41 PM
Hi @Supriya25
If you're using only Object.keys(result.errors).length > 0 in an if condition:
You can safely use either of these. Both are functionally identical.
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 11:01 AM
Hi,
I think the issue is that you may need close the "object.keys" code after the "+" sign. I think it may be interpretting it in correctly unless you have that piece of code properly defined. I did use a tool to rewrite it the code...not sure if this is more than what you may need. Attaching the file in case you want to try it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2025 02:05 PM
Object.keys(result.errors).length > 0 I would like to use in IF-CONDITTION
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) )