Can you reclassify a CI using a script?

Kit Sanders2
Kilo Contributor

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

1 ACCEPTED SOLUTION

Please use   the before business rule and let me know the output if you can find the ci with the new class.


View solution in original post

9 REPLIES 9

avinash kumar
Tera Expert

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


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();


}


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);


}


Thanks but this is not the issue. I added action.setRedirect(current); to the script but got the same "record not found" error