Populate a field with default value in Transform Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 01:03 AM
Hello folks,
I'm currently in the midst of trying to process a default value on os_domain field in a Transform Map script, I'm trying to have the transform map run and if a name matches certain criteria then the os_domain field will be populated with a default value.
i.e. if 'name' = 'AB-' then populate 'os_domain' to 'Intune'.
Furthermore, data is provided from a 3rd party source which does not pass through any value for this criteria, it reconciles data and then the computer table is populated. I have tried couple of methods but both failed to process.
This is the current script.
(function runTransformScript(source, map, log, target, import_set /*undefined onStart*/ ) {
var snowlog = new x_snsab_snow_catal.SnowLog();
snowlog.setTransformLog(log);
ignore = true;
var ciClassMapping = new CIClassMapping();
var cmdbUtilScoped = new CMDBTransformUtilScoped();
var cmdbUtil = new global.CMDBTransformUtil();
cmdbUtil.setDataSource('SnowSoftware');
// Determine the target ServiceNow class name based on certain attributes
var className = ciClassMapping.mapToClass(source.u_operatingsystem, source.u_hypervisorname, source.u_isserver, source.u_isvirtual, source.u_isportable);
// Check if the CI class is an IP address class; if yes, skip the import
if (className === 'cmdb_ci_ip_address') {
snowlog.debug('[SNOW_CMDB] Skipping import for IP address class.');
return;
}
var inputPayload = cmdbUtil.buildInputPayload(source, map, log);
inputPayload = cmdbUtilScoped.setCiClass(inputPayload, className);
// Proceed with reconciliation for non-IP address classes
cmdbUtil.identifyAndReconcileFromPayload(inputPayload, map, log);
cmdbUtilScoped.updateTransformStats(cmdbUtil, map, import_set);
if (cmdbUtil.hasError()) {
snowlog.error('[SNOW_CMDB] Computer transform : {0}', cmdbUtil.getError());
return;
}
var sysId = cmdbUtil.getOutputRecordSysId();
if (sysId.length === 0) {
snowlog.error('[SNOW_CMDB] Computer transform : did not get a valid sys id');
return;
}
// snowlog.debug('[SNOW_CMDB] Imported CI "{0}" with payload: {1}', sysId, cmdbUtil.getOutputPayload());
var func = new TransformFunctions();
func.addOrUpdateSysIdTable(source.u_cid, source.u_id, sysId);
})(source, map, log, target, import_set);
I would greatly appreciate any suggestions or recommendations you can provide.
Thanks