- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2016 04:30 AM
Is it possible to reclassify a CI by using a script?
I know it is possible to manually reclassify a CI by updating the Class (sys_class_name) on the form, but if I change the sys_class_name using a script, this results in a "record not found" error" on the CI.
From what I can gather, when the CI class is manually changed, a process runs in the background which deletes the CI from the old table and inserts it with the same sys_id into the new table. It seems that when the sys_class_name is changed by a script, this process in not invoked.
Any help gratefully received
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2016 05:59 AM
Please use the before business rule and let me know the output if you can find the ci with the new class.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2016 05:11 AM
Hi Kate,
If the process is a business rule, you need to call setWorkflow(true) in the script you are writing. This will allow the BR to run;
Hope this helps.
Regards,
Avinash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2016 05:35 AM
I tried it, but it makes no difference. Here is a simplified version of the BR (running on the cmdb_ci_computer table):
function onAfter(current, previous) {
current.sys_class_name = 'cmdb_ci_server';
current.setWorkflow(true);
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2016 05:38 AM
Wrote a before business rule and ryn it on cmdb_ci table
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
current.sys_class_name='cmdb_ci_web_server';
action.setRedirect(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2016 05:44 AM
Thanks but this is not the issue. I added action.setRedirect(current); to the script but got the same "record not found" error