Split a string on a Transform Map Script with multiple splits

Adam Wood
Tera Contributor

Hi

 

I have an issue when importing data from Intune where the IMEI imports as: 

 

Primary:33445566778899,CTSubscriptionSlotTwo:11223344556677

 

I want to show just the first IMEI EG 33448866778899

 

I am using the following script but this only splits by the : and give a value of:

 

33445566778899,CTSubscriptionSlotTwo

 

Please could you advise what is missing from the script to remove all noise and just show the first IMEI . 

 

 

I have added a comma as so .split(':,'); but this just give the original value without any splits 

 

answer = (function transformEntry(source) {
var imei = source.u_imei.toString().split(':');
if (imei.length == 1) {
return imei[0];
} else {
return imei[1];
}
})(source);

 

Any help would be most appreciated 

 

Thank you 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Adam Wood Here is the updated script. 

answer = (function transformEntry(source) {
var imei = source.u_imei.toString().split(',')[0].split(':')[1]);
return imei; //Will return 33445566778899
})(source);

Please mark this answer correct and helpful if it manages to address your issue.

View solution in original post

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Adam Wood Here is the updated script. 

answer = (function transformEntry(source) {
var imei = source.u_imei.toString().split(',')[0].split(':')[1]);
return imei; //Will return 33445566778899
})(source);

Please mark this answer correct and helpful if it manages to address your issue.

Bert_c1
Kilo Patron

Hi,

 

Here's an example to get what I believe you want.

 

var testStr = "Primary:33445566778899,CTSubscriptionSlotTwo:11223344556677"
var strArray = testStr.split(',');
gs.info("First is: " + strArray[0] + ". Second is: " + strArray[1]);
var strValueArray = strArray[0].split(':');
gs.info("First value is: " + strValueArray[1]);

which results in:

*** Script: First is: Primary:33445566778899. Second is: CTSubscriptionSlotTwo:11223344556677
*** Script: First value is: 33445566778899