Transform Script: Split String Value with Backslash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-10-2020 06:13 AM
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?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-10-2020 08:03 AM
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:
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-10-2020 08:12 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-10-2020 08:44 AM
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)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-12-2022 07:36 AM
It worked thank you!