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.

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
Mega 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.