Fix script for update the assignment group to original assignment group

Barathk
Tera Contributor

Hi All,

Fix script for update the assignment group to original assignment group.
I have created new field as original assignement group and created a BR for update the assignment group details to the original assignment group.

data updating fine after creating the BR for new sctasks.

I want to update the old task as well , can anyone please help for the fix script to update the assignment group to the original assignment group.

I want to update the first assignment group what ever when ticket is created.

 

var sctask = new GlideRecord('sc_task');
sctask.setLimit(100);
sctask.query();

while (sctask.next()) {
var originalGroup = sctask.getValue('assignment_group');
if (originalGroup) {
sctask.setValue('u_original_assignment_group', originalGroup);
sctask.setWorkflow(false); // Prevents running business rules and workflows
sctask.update();
gs.log('Task ' + sctask.number + ' successfully updated to original assignment group.');
} else {
gs.log('Original assignment group not found for task ' + sctask.number);
}
}

3 REPLIES 3

Pratiksha
Mega Sage
Mega Sage

add one more setvalue?

Sanjeev Kumar1
Kilo Sage

Hi Barathk,

 

You need to check your "metric_instance" table for historical data.

run your logic on it and update task data.

Thanks,

Sanjeev Kumar

 

Sumanth16
Kilo Patron

Hi @Barathk ,

 

You can use sys_audit table to get old value. But this table is very big in the number of rows and might affect the performance of the system.

 check the replies and you will find the code in this question.

https://community.servicenow.com/community?id=community_question&sys_id=06d2e119db7323c0fece0b55ca96...

You can use that as reference and can modify as per your requriement.

Mark the comment as a correct answer and also helpful if it helps.

 

Thanks & Regards,
Sumanth Meda