IntegrationHub OnBefore script not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2025 08:32 AM
Hi all,
I am using IntegrationHub to take an Excel file and transform the data to the Contract, Asset, and Assets Covered tables.
On the integration, I have a simple OnBefore script where if the Asset Type column on the Excel document is "Workstations" or "Notebooks", set the PO Number to "94904", but it does not work. I've looked at documentation for similar tasks and tried various iterations of this script but can't find a reason why this wouldn't work.
Why might this be?
(function onBefore(source, target, importLog) {
if(source.u_asset_type == "Workstations" || source.u_asset_type == "Notebooks")
source.u_po_number = '94904';
})(source, target, importLog);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2025 09:10 AM
Hi @DylanBlumenberg ,
You are assigning to source.u_po_number. Is that be target field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2025 09:14 AM
Hi @pavani_paluri, I think I need clarification on how these scripts affect the data. In an OnBefore script, is the target a staging table or would the target be the final table that the data is being imported to, in this case, ast_contract?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@DylanBlumenberg -
I was able to finally fix the issue. The issue with IH-ETL is it doenst treat the target as a gliderecord object. It treats as a JSON object. So setting target.po_number = "9404" doesnt work.
The solution is to write an onAfter script like below.
(function onAfter(source, target, importLog) {
// Parse the target JSON to get sys_id of the record you want to update
for (var tableName in target) {
var records = target[tableName];
if (records && records.length > 0) {
var sys_id = records[0].sys_id;
// Now update the record with GlideRecord
var gr = new GlideRecord(tableName);
if (gr.get(sys_id)) {
gr.u_po_number = '94904';
gr.update();
}
}
Please try and let me know how if this solves your issue.
Thanks,
BV
}
})(source, target, importLog);
