To auto-populate printer CIs name as serial number + model name.

PriyaRaj
Tera Contributor

Hi All,

When we create printer CIs, the name of printer should auto-populate as serial number + model name. 

Model name field is not available on printers table but model id is available. Kindly let me know how we can achieve this.

 

Thanks in Advance!!

2 REPLIES 2

Peter Bodelier
Giga Sage

Hi @PriyaRaj 

 

Create a Business Rule with below script, or use this as default value for the name field.

 

var printerName = current.serial_number + ' - ' + current.model_id.name;
current.name = printerName;

Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Anand Kumar P
Giga Patron
Giga Patron

Hi @PriyaRaj ,

Write after insert business rule in cmdb_ci_printer table add below script.

 

(function executeRule(current, previous /*null when async*/) {
    var model = new GlideRecord('cmdb_model'); 
    if (model.get(current.model_id)) {
        current.name = current.serial_number + ' ' + model.name;
    }
})(current, previous);

 

Thanks,

Anand