- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2018 06:31 AM
Hello, I have a UI Action(related link) which was built on cmdb_hardware table to take care of duplicates. This UI Action is available on each CI in the hardware table. This UI Action checks for tickets, tasks etc and performs it's action. The issue here is.. Script in the UI Action always looks for incident, task table to find the tickets of the CI each time when user click on the link. I think gliding multilpe larger tables slowing down the UI Action.
When we had the health check with ServiceNow, this specific script came out as slow running script. Is there any way to make this UI Action run faster than before using script include or something. Please suggest, Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2018 07:08 AM
Script include cannot be used, You can however move the deletion part into an event and script action for its execution.
The script will also require lot of optimization like
1) encodedQuery can be used instead of multiple addQuery()
2) You could use updateMultiple() instead of update() within the while loop. This will process the change in a single run instead of different loops on different tables
3) Separating the logic into 2 different parts:
a) Identifying the duplicates
b) Replacing the CIs on all task
c) Deleting them all together in an event
Lot of rework!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2018 06:33 AM
Hello,
Can you paste your script here so we could check on it? You could move it to a background event queue if it is holding back users on form.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2018 06:37 AM
var taskNumber = " ";
var dup_sysID = " ";
var tableName = current.sys_class_name;
var configItem = current.name;
var sysID = current.sys_id;
var noDuplicate = new GlideRecord(tableName);
noDuplicate.addQuery('name', configItem);
noDuplicate.addQuery('sys_id','NOT IN',sysID);
noDuplicate.query();
if(noDuplicate.next() == ''){
gs.addInfoMessage('No duplicates exist');
}
var duplicate = new GlideRecord(tableName);//Changes the table accordingly
duplicate.addQuery('name', configItem);
duplicate.addQuery('sys_id','NOT IN',sysID);
duplicate.query();
while(duplicate.next()){
dup_sysID = duplicate.sys_id;
var rel = new GlideRecord("cmdb_rel_ci");
rel.addEncodedQuery("parent.sys_idLIKE"+dup_sysID+"^ORchild.sys_idLIKE"+dup_sysID+"^sys_created_by!=system^sys_created_by!=MID_SERVER");
rel.query();
while(rel.next()){
if(rel.parent == dup_sysID ){
rel.parent = sysID;
}else if(rel.child == dup_sysID ){
rel.child = sysID;
}
rel.update();
}
var task_tab = new GlideRecord ('task');
task_tab.addQuery('cmdb_ci', dup_sysID);
task_tab.query();
while (task_tab.next()){
taskNumber = task_tab.getValue('number');
task_tab.cmdb_ci = sysID;
task_tab.update();
}
var taskTable = new GlideRecord ('task_ci');
taskTable.addQuery('ci_item', dup_sysID);
taskTable.addQuery('task' ,'!=' ,taskNumber );
taskTable.query();
while (taskTable.next()){
var additionalTasks = taskTable.getDisplayValue('task');
taskTable.ci_item = sysID;
taskTable.update();
}
if(current.ip_address == ''){
var ipAddress = duplicate.getValue('ip_address');
if(ipAddress == ''){
}else{
current.ip_address = ipAddress;
}
}
if(duplicate.u_rbac_d == true){
current.u_rbac_d = true;
}
var grcInfra = new GlideRecord('sn_grc_infrastructure');
grcInfra.addQuery('u_configuration_item', dup_sysID);
grcInfra.query();
while(grcInfra.next()){
grcInfra.u_configuration_item = sysID;
grcInfra.update();
}
duplicate.deleteRecord();
gs.addInfoMessage(dup_sysID+' has been deleted. CI associations & relationships are moved to: Master CI - '+sysID+' (' +configItem+ ')');
gs.addInfoMessage(task_tab.getRowCount()+' Incident/Problem/Change have been moved to: Master CI - '+sysID+' (' +configItem+ ')');
gs.addInfoMessage(taskTable.getRowCount()+' Affected by Tasks have been moved to: Master CI - '+sysID+' (' +configItem+ ')');
gs.addInfoMessage(rel.getRowCount()+' relationship(s) have been moved to: Master CI - '+sysID+' (' +configItem+ ')');
}
current.update();
action.setRedirectURL(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2018 06:54 AM
Are these duplicates added by Discovery?
Why don't you run it as a scheduled job instead of using a UI action? You could make it automated and the results can be logged in System logs. The script is doing lot of processing on CI related tables, Task related tables. The deleteRecord is one of the most time consuming operation to perform on the UI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2018 07:00 AM
We've multiple sources like bulk uploads, discovery, sccm and some other integration. I can't really use the scheduled job as this UI Action only runs on one CI each time when ever user wanted to remove duplicate but it looks thru different tables as you said. Do you think I can use script includes to avoid slow transaction? Thanks for looking into this.