CI is creating an Asset with the link but the asset link is not populating on the CI.

holly-t
Tera Guru

I have been having an issue and I have opened a HI ticket but not getting very much traction.

We have cssm and discovery running. I can recreate my issue fairly easy.

I can see the CI being created, the Model gets created, the Asset gets created and on that asset the CI field(link) gets populated but then the Asset field(link) on the CI does not get populated. Because of that I end up with many asset duplicates because every update to that CI creates a new Asset.

I really think the whole issue is why is the Asset field(link) not updating back onto the CI.   ACL? Script? Has anyone else ever had this issue??

1 ACCEPTED SOLUTION

holly-t
Tera Guru

OMG I think I found it. I was searching other posts about "java.sql.BatchUpdateException: Duplicate entry" and read about before scripts that should not contain update(). Well look what I found. This is a before script and when I turned if off, everything worked as designed with the exception of the asset tag did not get populated.




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


if (current.cost<=2000)


{var str = current.model.manufacturer.name;


  var ser = current.serial_number;


  var res = str.slice(0, 3);


  if (current.model.manufacturer.nil()){


    current.asset_tag=ser;


  }


else if (current.serial_number.nil()){


  current.asset_tag=res;


}


else {


  current.asset_tag=res+"-"+ser;


}


current.update();


var ca = new AssetAndCISynchronizer();


ca.syncRecords(current, 'cmdb_ci');


}


})(current, previous);


View solution in original post

18 REPLIES 18

Dear Holly,



What is the cmdb table name that we are looking at?



I checked the scripted include(AssetAndCISynchronizer ) and the BR that invokes it from cmdb_ci table. If you look at the condition field, you will see that it wont invoke the BR unless asset value is present. Wondering how this BR is executing if the Asset column is empty on the CI record.



find_real_file.png




Thanks


Anil


holly-t
Tera Guru

OMG I think I found it. I was searching other posts about "java.sql.BatchUpdateException: Duplicate entry" and read about before scripts that should not contain update(). Well look what I found. This is a before script and when I turned if off, everything worked as designed with the exception of the asset tag did not get populated.




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


if (current.cost<=2000)


{var str = current.model.manufacturer.name;


  var ser = current.serial_number;


  var res = str.slice(0, 3);


  if (current.model.manufacturer.nil()){


    current.asset_tag=ser;


  }


else if (current.serial_number.nil()){


  current.asset_tag=res;


}


else {


  current.asset_tag=res+"-"+ser;


}


current.update();


var ca = new AssetAndCISynchronizer();


ca.syncRecords(current, 'cmdb_ci');


}


})(current, previous);


I would comment that current.update() ( obviously ) but to keep asset_tag field same as serial number on the asset record ( alm_asset) a business rule on that table would do.