Robust Transform Map - how to calculate the value for a target field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 03:14 AM
Hi,
We are setting up the service graph connector for Crowdstrike and after the initial load I can see a bunch of errors. Some of these relate to Crowdstrike not passing over values for mandatory attributes in the target class ... for example -
"REQUIRED_ATTRIBUTE_EMPTY","message":"Missing mandatory field [owned_by] in table [cmdb_ci_hardware]. Add input value for mandatory field in payload"}]
As Crowdstrike doesn't contain this information I need to calculate it as part of the transform and then set the value. We have multiple companies in our instance and as such the owned by will be defaulted to a specific IT owner for each. For example -
Company a = person a
Company b = person b
and so forth.
I can't see anywhere in the robust transform map that allows me to calculate the target field based on source data. This is straight forward in a 'normal' transform map but I can't find anywhere to perform the calculation.
Has anyone does this before and can help?
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 03:32 AM
Hi @Steven Watts2,
To set a default `owned_by` value based on the company in ServiceNow, follow these steps:
1. Create a Transform Script:
(function runTransformScript(source, map, log, target) {
var company = source.company.toString().toLowerCase();
var ownedBy = '';
switch (company) {
case 'companya':
ownedBy = 'persona';
break;
case 'companyb':
ownedBy = 'personb';
break;
default:
ownedBy = 'default_person'; // Optional default
break;
}
target.owned_by = ownedBy;
})(source, map, log, target);
2. Apply the Script:
- Go to `System Definition > Transform Maps`.
- Select your Crowdstrike transform map.
- Add or edit the `owned_by` field mapping.
- Choose "Advanced" and paste the script in the Transform Script field.
3. Test:
- Run a test import to verify the `owned_by` field is set correctly based on the company.
Thank you, please make helpful if you accept the solution.