Fix Script

yoli1
Tera Contributor

Hi Team can someone explain to me what is a fix script so i created a business role that change the statut based on a state

and i need to create a fix script to update  initially all the records that have that state to the correct statut

Thanks!

1 ACCEPTED SOLUTION

SwarnadeepNandy
Mega Sage

Hello @yoli1,

 

A fix script is a server-side JavaScript code that runs after an application is installed or upgraded. You can use fix scripts to make changes that are necessary for the data integrity or product stability of an application, such as adding, updating, or deleting data, rules, scripts, or property settings.

If you created a business rule that changes the status based on a state, and you want to update all the existing records that have that state to the correct statuses, you can create a fix script that queries the table and updates the status field accordingly. For example, you can use the following code to update the status of all incidents that have the state “New” to “Open”:

 

var gr = new GlideRecord('incident');
gr.addQuery('state', 'New');
gr.query();
while (gr.next()) {
  gr.status = 'Open';
  gr.update();
}

 

You can modify the code to suit your needs and test it before running it on production. For more details on how to create, test, and run fix scripts, see this article or this article. I hope this helps. 😊

 

Best Regards,

Swarnadeep Nandy

View solution in original post

7 REPLIES 7

Anurag Tripathi
Mega Patron
Mega Patron

Fix Script is a Server side script that can be used on demand. 

You can create a fix script to loop through the records and update the status. Add Glide Record query on the same.

Create a fix script (servicenow.com)

 

-Anurag

SwarnadeepNandy
Mega Sage

Hello @yoli1,

 

A fix script is a server-side JavaScript code that runs after an application is installed or upgraded. You can use fix scripts to make changes that are necessary for the data integrity or product stability of an application, such as adding, updating, or deleting data, rules, scripts, or property settings.

If you created a business rule that changes the status based on a state, and you want to update all the existing records that have that state to the correct statuses, you can create a fix script that queries the table and updates the status field accordingly. For example, you can use the following code to update the status of all incidents that have the state “New” to “Open”:

 

var gr = new GlideRecord('incident');
gr.addQuery('state', 'New');
gr.query();
while (gr.next()) {
  gr.status = 'Open';
  gr.update();
}

 

You can modify the code to suit your needs and test it before running it on production. For more details on how to create, test, and run fix scripts, see this article or this article. I hope this helps. 😊

 

Best Regards,

Swarnadeep Nandy

@yoli1,

If my answer solves your problem, can i please request you to mark my answer correct. It will be useful for other community members.

 

Kind Regards,

Swarnadeep Nandy

Hi @SwarnadeepNandy what does Unloadable stands for when creating a fix script?