Synchronize custom field on cmdb_ci_computer and alm_hardware without adding to parent tables

brianbeauchamp
Tera Guru

I'm looking to synchronize a custom field [u_location_detail] on the Hardware asset table (alm_hardware) and Computer tables (cmdb_ci_computer). I see that I can use AssetAndCISynchronizer if I add both fields to the alm_asset and cmdb_ci tables. Unfortunately that adds u_location_detail to all extended tables below which is not wanted.

Any other thoughts on how to keep data synchronized between these two fields? Is there a best practice?

With parent tables such as task it is best practice not to add fields to task, is that not the case with cmdb/asset?

[Running on Jakarta]

1 ACCEPTED SOLUTION

brianbeauchamp
Tera Guru

Thanks, that's what I had tried to do initially but left it once I discovered AssetAndCISynchronizer

 

After business rule on alm_hardware

(function executeRule(current, previous /*null when async*/) {
var field = current.u_locationdetail;
    if (current.u_locationdetail != previous.u_locationdetail) {
        var ccc = new GlideRecord("cmdb_ci_computer");
        ccc.addQuery("table", "alm_hardware");
        ccc.addQuery("sys_id", current.ci);
        ccc.query();
        
        if (ccc.next()) {
                ccc.setValue("u_locationdetail", field);
                ccc.update();
        }
    }

})(current, previous);

 

After business rule on cmdb_ci_computer

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

	if (current.u_locationdetail != previous.u_locationdetail) {
		var ah = new GlideRecord("alm_hardware");
		ah.addQuery("ci", current.sys_id);
		ah.query();
		
		if (ah.next()) {
			ah.setValue("u_locationdetail", current.u_locationdetail);
			ah.update();
		}
	}

})(current, previous);

View solution in original post

2 REPLIES 2

Stewe Lundin
Mega Guru

Set up a business rule that tracks the change on either field and replicate the data to the corresponding field in the target table. 


  

brianbeauchamp
Tera Guru

Thanks, that's what I had tried to do initially but left it once I discovered AssetAndCISynchronizer

 

After business rule on alm_hardware

(function executeRule(current, previous /*null when async*/) {
var field = current.u_locationdetail;
    if (current.u_locationdetail != previous.u_locationdetail) {
        var ccc = new GlideRecord("cmdb_ci_computer");
        ccc.addQuery("table", "alm_hardware");
        ccc.addQuery("sys_id", current.ci);
        ccc.query();
        
        if (ccc.next()) {
                ccc.setValue("u_locationdetail", field);
                ccc.update();
        }
    }

})(current, previous);

 

After business rule on cmdb_ci_computer

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

	if (current.u_locationdetail != previous.u_locationdetail) {
		var ah = new GlideRecord("alm_hardware");
		ah.addQuery("ci", current.sys_id);
		ah.query();
		
		if (ah.next()) {
			ah.setValue("u_locationdetail", current.u_locationdetail);
			ah.update();
		}
	}

})(current, previous);