Unable to update the Assignee value on incident table and task table

pavam
Tera Contributor
 From the schedule Job i was trying to update the Assignee value and state Field values in the Incident and Task table 
with the below code.
I can successfully update assignee field with the below script , but state value is not getting update.
 
var t1= new GlideRecord('incident');
  t1.addQuery('assigned_to', username1);
  t1.addEncodedQuery(inctkts);
  t1.query();
 
  while(t1.next()){
 
if (t1.getRowCount() > 0) {
    
t1.setWorkflow(false);
t1.assigned_to=' ';
t1.state='1';
t1.update(); 
 
}
       } 
 
Can any one help on this to me.
 
Highly appreciated in advance for the help.
1 ACCEPTED SOLUTION

Hi @pavam,

 

I'm not sure you're quite understanding me. Can you test the script as a Scheduled Job against 1 specific ticket to ensure the script is working.

I've tested it and it works as expected which is pointing to the encoded query that is not shared.

You can test against a single record by adjusting the script similar to mine.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

View solution in original post

10 REPLIES 10

Bert_c1
Kilo Patron

Neither 'username1' or 'inctkts' is defined, I can't see how the script does anything.

sanasunilku
Mega Expert

Make sure you use the right value for state and remove the extra check. Set a valid user for assigned_to or leave it out.

var t1 = new GlideRecord('incident');
t1.addQuery('assigned_to', username1);
t1.addEncodedQuery(inctkts);
t1.query();

while (t1.next())

{
t1.setWorkflow(false);
t1.assigned_to = ''; 
t1.state = '1';
t1.update();
}

sanasunilku
Mega Expert

Make sure you use the right value for state and remove the extra check. Set a valid user for assigned_to or leave it out.
var t1 = new GlideRecord('incident');
t1.addQuery('assigned_to', username1);
t1.addEncodedQuery(inctkts);
t1.query();

while (t1.next()) {
t1.setWorkflow(false);
t1.assigned_to = ''; 
t1.state = '1'; 
t1.update();
}

Robbie
Kilo Patron
Kilo Patron

Hi @pavam,

 

I've tried to replicate the Scheduled Job on my PDI with a slight tweak to the script to isolate and test on one specific record.

The syntax looks correct but I've adjusted it slightly and it now works as expected. (You need to remove the space in between the quotes when setting the assigned to value.)

I'd also suggest checking against one record first to ensure it's working correctly before adding your encoded query as you may not be looking at the correct record. It's also good practice to print out some infomation and check numbers before executing an update.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

 

var t1 = new GlideRecord('incident');
t1.addQuery('number', 'INC0000020', );
//t1.addEncodedQuery(inctkts);
t1.query();
if (t1.next()) {
    if (t1.getRowCount() > 0) {
        t1.setWorkflow(false);
        t1.assigned_to = '';
        t1.state = '1';
        t1.update();
    }
}

 

Screenshot 2024-09-05 at 15.36.46.png