Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Transform Script: Split String Value with Backslash

Thomas_J_C
Mega Expert

Currently attempting to split some source string values for example:

"EXAMPLE-US-WEST\DC91P-NS-AP74" (I'd like to get the SECOND half of the string "DC91P-NS-AP74" from the value)

My current code is:

var bios = source.u_biosName.toString().split(/\\/)[1];

However, the string value comes up as undefined and if I put the string index to [0], the log message will come up as "EXAMPLE-US-WESTDC91P-NS-AP74" and will just replace the backslash. 

Any ideas how to split this source string values to get the second half of the value after the backslash?

 

 

8 REPLIES 8

Thomas_J_C
Mega Expert

Thanks for the helpful tips everyone. I've attached a snapshot of the source data that is being imported in an import set record below:

find_real_file.png

So the code would have to be dynamic and aim to split the value into the two strings between the backslash.

Would a transform script (onBefore) for the netbiosName source field aimed at replacing the backslash value be the best option for assigning an extra backslash to the value for future string splitting?

 

I think you're going to have trouble replacing a backslash once it's in a string field even in the import set.  Can you hijack the data before it is imported?

I used a two-step approach to resolve this issue:

1.) I created an onBefore transform script on the transform map to set the import set table's record values by this code:

var bios = source.u_name.toString();
var biosName = bios.replace(/\\/, ":");
source.u_name = biosName;

2.) Then I used a field level source script to easily remove the source string value with the following code:

var result = source.u_name.toString().split(":")[1];

return result; (with the target correct target field)

Prabu Velayutha
Mega Sage

It worked thank you!