- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 12:40 AM
We have a requirement to update the Status field based on the Retired checkbox. If u_retired is true, then install status should change to "Retired" and if it is false, it should be "Installed". We need the exact count of rows updated after executing the fix script. When we use the below script it's not showing the correct count. Please assist.
var sr= new GlideRecord('cmdb_ci_server');
var count=0;
sr.query();
gs.log("Total Rows:" +sr.getRowCount());
while(sr.next())
{
if(sr.u_retired==false)
{
//Updates the Status to "Installed" if Retired Checkbox is unchecked
sr.install_status = 1;
}
if(sr.u_retired==true)
{
//Updates the Status to "Retired" if Retired Checkbox is checked
sr.install_status = 7;
}
sr.update();
count++;
}
gs.log("Updated Rows:" +count);
If there is any possibilities of getting the exact count using sys_update_on field it would be helpful.
Solved! Go to Solution.
- Labels:
-
Discovery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 12:48 AM
Hi,
please use 2 counts for retire and install
updated script below
var sr= new GlideRecord('cmdb_ci_server');
var countRetired = 0;
var countInstalled = 0;
sr.query();
gs.log("Total Rows:" +sr.getRowCount());
while(sr.next())
{
if(sr.u_retired==false)
{
//Updates the Status to "Installed" if Retired Checkbox is unchecked
sr.install_status = 1;
countInstalled++;
}
if(sr.u_retired==true)
{
//Updates the Status to "Retired" if Retired Checkbox is checked
sr.install_status = 7;
countRetired++;
}
sr.update();
count++;
}
gs.log("Updated countRetired Rows:" +countRetired);
gs.log("Updated countInstalled Rows:" +countInstalled);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 12:48 AM
Hi,
please use 2 counts for retire and install
updated script below
var sr= new GlideRecord('cmdb_ci_server');
var countRetired = 0;
var countInstalled = 0;
sr.query();
gs.log("Total Rows:" +sr.getRowCount());
while(sr.next())
{
if(sr.u_retired==false)
{
//Updates the Status to "Installed" if Retired Checkbox is unchecked
sr.install_status = 1;
countInstalled++;
}
if(sr.u_retired==true)
{
//Updates the Status to "Retired" if Retired Checkbox is checked
sr.install_status = 7;
countRetired++;
}
sr.update();
count++;
}
gs.log("Updated countRetired Rows:" +countRetired);
gs.log("Updated countInstalled Rows:" +countInstalled);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 12:59 AM
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 01:39 AM
You are welcome
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader