Insert Record in Custom Table from Software Installations table

Nishant16
Tera Expert

Hi All, 

 

I have a custom table "u_license_data' which has a field 'u_software_installations' referencing to the Software Installations(cmdb_sam_sw_install)table.
Now whenever discovery inserts a new record into the Software Installation table i need to insert the same record in the custom table with the reference to software installations, for this i have setup a After Insert Business rule below which is not working and inserting empty reference records in the custom table.

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
    var gr= new GlideRecord('u_license_data');
    gr.initialize();
    gr.u_software_installations = current.getUniqueValue();
    gr.insert();

})(current, previous);

 

I tried to insert record manually in the software installation table if my business rule works, and it inserts the records correctly in the custom table, however when discovery inserts records in the software installation table the empty reference records are getting inserted into the custom table, can someone please suggest what could be issue and how to fix this?

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Nishant16 ,

Can you please try this script it before insert BR and if you really want to use in After Insert BR, you should check the order, there are some chances that some BR with lower order have setWorkFlow(true) or setAbortAction.

For Example: 

Your After BR  having order 100, and there is any other BR with order 90 and containing setWorkFlow(true) or setAbortAction so your BR will not execute in that condition

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards

Sarthak

View solution in original post

1 REPLY 1

Community Alums
Not applicable

Hi @Nishant16 ,

Can you please try this script it before insert BR and if you really want to use in After Insert BR, you should check the order, there are some chances that some BR with lower order have setWorkFlow(true) or setAbortAction.

For Example: 

Your After BR  having order 100, and there is any other BR with order 90 and containing setWorkFlow(true) or setAbortAction so your BR will not execute in that condition

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards

Sarthak