- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2025 11:36 AM
I have a requirement to ignore the insert of records into the hardware table if source.asset_type is a certain value. This is mapped to the Model Category field in the hardware table. I have the following onBefore script, however, it is not working.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var assetType = source.asset_type;
if(assetType == "Accessories" || assetType == "Components/Upgrades" || assetType == "Memory Module" || assetType == "Hybrid Work Solutions" && action == "insert"){
ignore = true;
}
})(source, map, log, target);
Am I using the right approach? The mapping for Model Category in this transform map takes source.asset_type and translates it to values that exist in our system with a script. That part works and I'm not sure if it affects this script functioning properly.
What am I doing wrong?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2025 10:33 PM
Hello @michaelsmith02 ,
You need to put parentheses around the OR conditions, else the "action" value will only be checked for the "Hybrid Work Solutions" type.
if ((assetType == "Accessories" || assetType == "Components/Upgrades" || assetType == "Memory Module" || assetType == "Hybrid Work Solutions") && action == "insert") {
ignore = true;
}
Or, if you want it to be more readable:
var typesToIgnore = [
'Accessories',
'Components/Upgrades',
'Memory Module',
'Hybrid Work Solutions'
]
if (typesToIgnore.includes(assetType) && action == "insert") {
ignore = true;
}
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2025 10:33 PM
Hello @michaelsmith02 ,
You need to put parentheses around the OR conditions, else the "action" value will only be checked for the "Hybrid Work Solutions" type.
if ((assetType == "Accessories" || assetType == "Components/Upgrades" || assetType == "Memory Module" || assetType == "Hybrid Work Solutions") && action == "insert") {
ignore = true;
}
Or, if you want it to be more readable:
var typesToIgnore = [
'Accessories',
'Components/Upgrades',
'Memory Module',
'Hybrid Work Solutions'
]
if (typesToIgnore.includes(assetType) && action == "insert") {
ignore = true;
}
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2025 02:34 PM
Ah, I see my mistake, adding parentheses around the "OR" statements worked! Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2025 12:20 AM
Your script has a logical grouping issue. The && action == "insert" condition currently applies only to "Hybrid Work Solutions" due to operator precedence.
You can modify your script using one of the following approaches:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var assetType = source.asset_type;
if (assetType == "Accessories" || assetType == "Components/Upgrades" || assetType == "Memory Module" || assetType == "Hybrid Work Solutions" && action == "insert") {
ignore = true;
}
})(source, map, log, target);
OR
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Check if the asset type is one of the specified types and the action is "insert"
if (["Accessories", "Components/Upgrades", "Memory Module", "Hybrid Work Solutions"].includes(source.asset_type) && action == "insert") {
// Ignore the record if the condition is met
ignore = true;
}
})(source, map, log, target);
Regards,
Siva