The CreatorCon Call for Content is officially open! Get started here.

Background script to query the value of a field

sigmachiuta
Kilo Guru

I am trying to run a BG script that should tell the sc_task records are in the state of 7 and updting them to a new value.   7 being the 'value' of the field.   When I run the query nothing is printed out.   I have verified there is in fact a record with that state but receive nothing in the window after i run the script.   There is also nothing in the log that would indicate an error.

var gr = new GlideRecord('sc_task')

gr.addQuery('state',7);

while (gr.next()){

gs.print('Number updated= '+ gr.number)

gr.state = 2;

gr.update();

}

1 ACCEPTED SOLUTION

Refresh the page, I believe security admin rights have been expired . Elevate your privileges again and open the background script and try now.


View solution in original post

5 REPLIES 5

Abhinay Erra
Giga Sage

You are missing gr.query(). After gr.addQuery(....); add   gr.query();



Thanks,


Abhinay



PS: Hit like, Helpful or Correct depending on the impact of the response


wow thanks I knew it was a stupid mistake somewhere


that is unusual after i added that i dont receive anything in the next window its just blank



var gr = new GlideRecord('sc_task')


gr.addQuery('state',7);


gr.query();


while (gr.next()){


gs.print('Number is '+ gr.number)




}


Refresh the page, I believe security admin rights have been expired . Elevate your privileges again and open the background script and try now.