Building a query issue on a fix script

PaulaaO
Mega Sage

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

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

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?

find_real_file.png

Returns only 1 record for me...all the rest have no description:

find_real_file.png

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:

find_real_file.png

gr.addEncodedQuery('paste_here');

So, result:

gr.addEncodedQuery('descriptionISNOTEMPTY');

And running script example returns just the 1 result:

find_real_file.png

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

4 REPLIES 4

Musab Rasheed
Tera Sage
Tera Sage

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();
}
Please hit like and mark my response as correct if that helps
Regards,
Musab

Thanks, unfortunately it hasn't worked, it still updated all records.

Does this help?

find_real_file.png

Allen Andreas
Administrator
Administrator

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?

find_real_file.png

Returns only 1 record for me...all the rest have no description:

find_real_file.png

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:

find_real_file.png

gr.addEncodedQuery('paste_here');

So, result:

gr.addEncodedQuery('descriptionISNOTEMPTY');

And running script example returns just the 1 result:

find_real_file.png

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

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!! 🙂