Help with transform field map script

Snowman15
Tera Expert

Hi all, 

I am struggling with a field map script, and could use some guidance from the community.

Due to limitations, the source spreadsheet columns cannot be modified, so I need to handle everything via scripting.

 

One of the source fields, source.u_softwaretype, contains values formatted like:
"GH001 - Software Not found"

What I need to do is:

  1. Extract just the code portion ("GH001") from the text.

  2. Perform a lookup in the x_software_list_code_mapping table where:

    • supplier = 'WILLIAMS'

    • code = 'GH001' (the extracted value)

  3. From the matched record, retrieve the serial_number field value. 

  4. Populate the target reference field with that serial_number field value.  

 

This is the script I tried so far but is not working:

Snowman15_0-1750098534478.jpeg

 

 

(function transformEntry(source) {
 
var match = source.u_softwaretype.match(/(GH\d{3})/);
if (!match) return "";

var extractedCode = match[1];

 
var gr = new GlideRecord('x_software_list_code_mapping');
gr.addQuery('supplier', 'WILLIAMS');
gr.addQuery('code', extractedCode);
gr.setLimit(1);
gr.query();

if (gr.next()) {
return gr.serial_number;
}

return "";
})(source);
 
 
Thank you
5 REPLIES 5

Muhammad Salar
Giga Sage

Hello @Snowman15 , try this,
gr.addQuery('code', extractedCode.toString());