- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 05:17 PM
Hi
I am trying to write an encoded query for the following condition - if state is closed (3) and parent sys_id matches current parent. How do I write this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 07:45 AM
😅Okay. I don't have testing environment so sorry for that I could not test the code and its output, still we will try to make it correct.
var parent = current.regulatory_task;
gs.addInfoMessage("parent = " + parent);
var totalHrs = 0;
var grRegActTsk = new GlideRecord('sn_grc_reg_change_regulatory_action_task');
// Combine conditions using ^ for AND
grRegActTsk.addEncodedQuery("state=3^regulatory_task=" + parent);
grRegActTsk.query();
while (grRegActTsk.next()) {
if (!isNaN(parseInt(grRegActTsk.u_actual_hours, 10))) {
totalHrs += parseInt(grRegActTsk.u_actual_hours, 10);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 07:21 AM
Hello @sayalisheth ,
Please give a try to the code below and see how it works for you.
var parent = current.regulatory_task;
gs.addInfoMessage("parent = " + parent);
var totalHrs = 0;
var grRegActTsk = new GlideRecord('sn_grc_reg_change_regulatory_action_task');
// Remove the semicolon at the end of the next line
grRegActTsk.addEncodedQuery("state=3^regulatory_task=" + parent);
grRegActTsk.query();
while (grRegActTsk.next()) {
// Remove the semicolon at the end of the next line
if (!isNaN(parseInt(grRegActTsk.u_actual_hours, 10))) {
totalHrs += parseInt(grRegActTsk.u_actual_hours, 10);
}
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 07:28 AM
that didn't work. The query is returning 0 results, so it won't go into the while loop. I know there are 2 records that match the query..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 07:34 AM
@sayalisheth Oh okay then lets try with the below one.
var parent = current.regulatory_task;
gs.addInfoMessage("parent = " + parent);
var totalHrs = 0;
var grRegActTsk = new GlideRecord('sn_grc_reg_change_regulatory_action_task');
grRegActTsk.addEncodedQuery("state=3^regulatory_task=" + parent);
grRegActTsk.query();
while (grRegActTsk.next()) {
if (!isNaN(parseInt(grRegActTsk.u_actual_hours, 10))) {
totalHrs += parseInt(grRegActTsk.u_actual_hours, 10);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 07:40 AM
😞 no luck...
if I add a query to just search based on sys_id it finds the records. If I add a query to just search based on the state, it finds records then as well. If I put those together in the encoded query, then it doesn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 07:45 AM
😅Okay. I don't have testing environment so sorry for that I could not test the code and its output, still we will try to make it correct.
var parent = current.regulatory_task;
gs.addInfoMessage("parent = " + parent);
var totalHrs = 0;
var grRegActTsk = new GlideRecord('sn_grc_reg_change_regulatory_action_task');
// Combine conditions using ^ for AND
grRegActTsk.addEncodedQuery("state=3^regulatory_task=" + parent);
grRegActTsk.query();
while (grRegActTsk.next()) {
if (!isNaN(parseInt(grRegActTsk.u_actual_hours, 10))) {
totalHrs += parseInt(grRegActTsk.u_actual_hours, 10);
}
}