Query Sys_Journal_Field table using if statement in workflow

Sam Motley
Giga Guru

hi all, 

 

i'm trying to run a query on an incident record in a workflow which should take the sys_id of the incident ticket reference and query the sys_journal_field table along with the value of the worknote being passed....

My query is returning true constantly despite the worknote not existing 

 

i'm hoping this is a simple thing but i'm not sure where i'm going wrong with the script if anyone could take a look? 

I'd really appreciate it! 

Cheers. 

 

Code below: 

 

answer = ifScript();
function ifScript() {

 

var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id',current.sys_id);
gr.addQuery('Value','Ticket Auto-Assigned - Flow Complete and will not run again');
gr.query();
if( gr.next() ) {

return 'yes';

} else {


return 'no';


}
}

1 ACCEPTED SOLUTION

Vasantharajan N
Giga Sage
Giga Sage

Please try this one

You mentioned the incorrect field for Value. It should be "value"

answer = ifScript();

function ifScript() {
    var gr = new GlideRecord('sys_journal_field');
    gr.addQuery('element_id', current.sys_id);
    gr.addQuery('value', 'Ticket Auto-Assigned - Flow Complete and will not run again');
    gr.query();
    if (gr.next()) {
        return 'yes';
    } else {
        return 'no';
    }
}

 


Thanks & Regards,
Vasanth

View solution in original post

4 REPLIES 4

Vasantharajan N
Giga Sage
Giga Sage

Please try this one

You mentioned the incorrect field for Value. It should be "value"

answer = ifScript();

function ifScript() {
    var gr = new GlideRecord('sys_journal_field');
    gr.addQuery('element_id', current.sys_id);
    gr.addQuery('value', 'Ticket Auto-Assigned - Flow Complete and will not run again');
    gr.query();
    if (gr.next()) {
        return 'yes';
    } else {
        return 'no';
    }
}

 


Thanks & Regards,
Vasanth

Hi @Vasantharajan N 

thanks for your reply, very silly mistake by me to miss cheers for pointing out.

 

I've amended to 'value' but my workflow is still not querying correctly still. It now goes straight to no even though the worknote exists

Can you please confirm whether incident reference is a variable on your catalogue item.

if yes then please update the line below with right variable name that hold incident reference

gr.addQuery('element_id', current.variables.varable_name.toString());

 


Thanks & Regards,
Vasanth

hi, 

it was a bit odd to be honest when copying and pasting the worknote i had a strange red dot i was removing i tried leaving it and for some reason that was required to make the query work properly!

SamMotley_0-1670935342198.png

not sure why but hey ho that's service-now in a nutshell 

thanks for your help !