- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 08:15 AM
Hi All,
I have the below code but its not working as expected. I am storing few numbers in RITM description and wanted to obtain the max number.
----------------
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 11:21 AM
Forcing the retrieved description to a string should remedy that
var descArr = gr.description.toString().split(',');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 10:35 AM
Hi @dvelloriy ,
Try this out
var ritmAT = [];
var gr = new GlideRecord("sc_req_item");
gr.addEncodedQuery("cat_item=4410e34a1b649a101a29eb98b04bcbfe^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()");
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr.query(); //101, 102
gs.info("$$$Records in RITM table: " + gr.getRowCount());
while (gr.next()) {
ritmAT = gr.getValue('description').split(','); //101, 102
}
ritmAT = ritmAT.map(function(i){return parseInt(i)});
gs.info("$$$ RITMAT: " + ritmAT);
var maxNum = Math.max.apply(null, ritmAT); //102
gs.info("$$$Max Number: " + maxNum);
Mark this has helpful and correct if it works.
Thanks,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 11:19 AM
Thanks Chaitanya, tried it but its still not working. Now its not even displaying the info message for max number so i guess its getting failed before that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 10:37 AM
If you are storing more than just one number value in each RITM description, then your array is going to contain members that are not numbers (rather one member will be "243020001,243020002") so a math method will not return a number. If this is the case, you can use something like this:
var ritmAT = [];
var gr = new GlideRecord("sc_req_item"); gr.addEncodedQuery("cat_item=4410e34a1b649a101a29eb98b04bcbfe^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()");
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr.query(); //101, 102
gs.info("$$$Records in RITM table: " + gr.getRowCount());
while (gr.next()) {
var descArr = gr.description.split(',');
for (var i = 0; i < descArr.length; i++) {
ritmAT.push(descArr[i]);
}
}
gs.info("$$$ RITMAT: " + ritmAT);
var maxNum = Math.max.apply(null,ritmAT); //102
gs.info("$$$Max Number: " + maxNum);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 11:18 AM
Thanks Brad. I tried this approach as well, now its giving an error message:
Error: Cannot find function split in object .,Detail: Cannot find function split in object .
Updated script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 11:21 AM
Forcing the retrieved description to a string should remedy that
var descArr = gr.description.toString().split(',');