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

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();
}

Hi Sanasunilku,

 

The code is working me in background script,

but when i am executing the same code through schedule job ,

t1.assigned_to = '';   is updating and 

t1.state = '1';   is not getting update.

 

so , i just want to know what other parameters are  effecting to my code.

 

Thankyou.

pavam
Tera Contributor

When i am hitting the above script in the background script it is working fine.

but when i am running the same script  through schedule job, 

 

Assigned_to  value is updating  and state='1' is not updating in the table.

Hi @pavam,

 

Can you entertain me and adjust your script similar to mine (by targeting a single ticket) as a scheduled job and confirm the behavior please.

I've tested and confirmed this works as a Scheduled Job (Specifically a Scheduled Script) for an individual ticket.

 

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

pavam
Tera Contributor

Hi Robbie,

 

below is the code.

 


var t1 = new GlideRecord('incident');
t1.addQuery('assigned_to', username1);
t1.addEncodedQuery("numberSTARTSWITHINC^active=true^stateIN2,3,6");
t1.query();

while (t1.next())

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

 

you can add  "username1" any sys_id value from sys_user table.

 

what other parameters are effecting