Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

IntegrationHub OnBefore script not working

DylanBlumenberg
Tera Guru

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);

 

 

17 REPLIES 17

pavani_paluri
Tera Guru
Tera Guru

Hi @DylanBlumenberg ,

 

You are assigning to source.u_po_number. Is that be target field.

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Pavani P

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?

PavanBV
Tera Guru

@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);