Update problem work notes using a fix script

Sharon Williams
Tera Contributor

Hello, I created a fix script (see below) to update the state and work notes of certain problem records.  The fix script is not completely working.  The state is getting updated, however there is no update to the work notes after I run the fix script.  Can someone help me with this?  Thanks...

 

var grProb = new GlideRecord('problem');
grProb.addEncodedQuery('stateNOT IN101,102,103,104,106,107^;
grProb.query();
while (grProb.next()) {
     grProb.state = 107;
     grProb.setValue.work_note = "This problem record was closed via a script in STRY0240331 because it was in an improper state which was not allowing it to be closed.";
     grProb.update();
}

6 REPLIES 6

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Sharon Williams ,

 

Please use, grProb.work_notes = "......";

Updated Script:

var grProb = new GlideRecord('problem');
grProb.addEncodedQuery('stateNOT IN101,102,103,104,106,107^;
grProb.query();
while (grProb.next()) {
     grProb.state = 107;
     grProb.work_notes = "This problem record was closed via a script in STRY0240331 because it was in an improper state which was not allowing it to be closed.";
     grProb.update();
}

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

Hi Karan.  I tried the syntax that you suggested initially and it did not work.  Do I have to do some type of insert to update the work note with the new text?

Thanks Karan.  I had to update the code to:

grProb.work_notes.setJournalEntry('This problem record was closed via a script in STRY0240331 because it was in an improper state which was not allowing it to be closed.'); 

Prateek kumar
Mega Sage

Try below

var grProb = new GlideRecord('problem');
grProb.addEncodedQuery('stateNOT IN101,102,103,104,106,107^;
grProb.query();
while (grProb.next()) {
     grProb.state = 107;
     grProb.setValue("work_notes", "This problem record was closed via a script in STRY0240331 because it was in an improper state which was not allowing it to be closed.");
     grProb.update();
}

Please mark my response as correct and helpful if it helped solved your question.
-Thanks