
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 09:31 AM
Hi,
I am struggling to build the query for a Fix Script in which I should only update records where a specific string field does hold data.
Requirement: need to add whatever is in description field from risk table into a work_note.
The trouble is that when I try to filter the list of risks by Description is not empty, the filter does not work and it returns also records where description field is blank.
The only filter I could make it work is Description is empty string, but then I would require the opposite of that which I could not see as an option.
How can I achieve this please? Any help is appreciated.
var gr = new GlideRecord('risk');
gr.addNotNullQuery('descriptionEMPTYSTRING');
gr.query();
while (gr.next()) {
gr.work_notes = gr.description.toString() + "tralala3";
gr.update();
}
Thank you.
Paula
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 10:05 AM
Hi,
My apologies, just to double-check...you're saying you've tried to use a filter for description is not empty and that did not work?
Can you perhaps share a screenshot of that? And we're talking about the description field...not short description, right?
Returns only 1 record for me...all the rest have no description:
Once you've got your filter set, right-click the last piece of the breadcrumb and choose "copy query", then in your script you'd use:
gr.addEncodedQuery('paste_here');
So, result:
gr.addEncodedQuery('descriptionISNOTEMPTY');
And running script example returns just the 1 result:
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 09:35 AM
Hi Paula,
What type of field is description.? normal multi line text or HTML.? try below.?
var gr = new GlideRecord('risk');
gr.addNotNullQuery('description');
gr.query();
while (gr.next()) {
gr.work_notes = gr.description.toString() + "tralala3";
gr.update();
}
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 10:00 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 10:05 AM
Hi,
My apologies, just to double-check...you're saying you've tried to use a filter for description is not empty and that did not work?
Can you perhaps share a screenshot of that? And we're talking about the description field...not short description, right?
Returns only 1 record for me...all the rest have no description:
Once you've got your filter set, right-click the last piece of the breadcrumb and choose "copy query", then in your script you'd use:
gr.addEncodedQuery('paste_here');
So, result:
gr.addEncodedQuery('descriptionISNOTEMPTY');
And running script example returns just the 1 result:
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 10:19 AM
Thanks Allen for the above - I just realised the reason why the filter was not working. I ran another fix script yesterday to concatenate in description field, values from both description and mitigation and seems this impacted the "emptiness" of the field; even though none would have any values and the result would still be a blank field, the system somehow did not recognise the updated description field as being empty.
I've cleared out all values from description and updated only 2 records and re-applied the filter and it worked. Lesson learned alright, happy I got to do this in my own instance :))))
Thank you!! 🙂