Issue with split - Multiline text variable

mohanambalnanja
Tera Contributor

Hi ,

 

I am trying to split multiline text variable in Business Rule with \n and space.

 

Trying with the below script. But it is not working.

 

Example Multi line variable = Test User1

                                                   User2

 

var fullNameSplit = fullName.split('\n');    //fullNameSplit.length = 2
 
        if (fullNameSplit.length > 1)    
        {
            fullName = fullNameSplit[1];        // Trying to take only the first line "Test User1" as a full name
        }
        var nameSplit = fullName.split(' ');   // Trying to split the space from the first line 
       
        if (nameSplit.length >= 0)
        {
            var firstName = nameSplit[0];   //  From the full name trying to take only the string "Test" as a first name
            var lastName = nameSplit[nameSplit.length -1];
         }
 
Someone please suggest on this . Thanks
2 REPLIES 2

Simon Christens
Kilo Sage

Hi

   fullName = fullNameSplit[1];        // Trying to take only the first line "Test User1" as a full name
Should be fullName = fullNameSplit[0]; 

  if (fullNameSplit.length > 1)    
        {
            fullName = fullNameSplit[1];        // Trying to take only the first line "Test User1" as a full name
/*THIS IS THE 2nd user - index starts with 0*/
        }
        var nameSplit = fullName.split(' ');   // Trying to split the space from the first line 

mohanambalnanja
Tera Contributor

Earlier I tried with [0] only, but it didn't give the expected result.  When I try print in log, it is coming in first place. I will try again with 0.

Thanks for your response.