- 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
‎01-31-2024 06:06 PM
Hi @sayalisheth please find below code
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2024 07:14 AM
as soon as I add the encoded query, I don't get any records. I should get 2. If I run the query separately, I do get some records. What else could be the issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2024 06:07 PM - edited ‎01-31-2024 06:10 PM
You need to use string concatenation:
grRegActTsk.addEncodedQuery("state=3^regulatory_task=" + parent);
This will use the value in the variable parent and "glue"/"join" it together with the string. See the aforementioned link for details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2024 06:18 PM
Hi @sayalisheth,
Use the parent variable in the query as below
grRegActTsk.addEncodedQuery("state=3^regulatory_task="+parent);
-Thanks
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution