Business rule to split the sentence when ends with dot ('.')

Deepa12
Tera Contributor

Hi,

Please advise how to split the sentence when ends with dot(.) while doing the update into customized field 'issues' column.

 

THanks,

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Deepa12 

something like this in business rule (Before insert/update)

// Get the current issues string
var issuesString = current.u_issues + '';

// Split by period
var issuesArray = issuesString.split('.');

// Prepare a new array for cleaned sentences
var cleanedIssues = [];

for (var i = 0; i < issuesArray.length; i++) {
    var issue = issuesArray[i].trim();
    if (issue) {
        cleanedIssues.push(issue + '.'); // Add the period back if you want
    }
}

// Join with newline character
current.u_issues = cleanedIssues.join('\n\n');

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

SANDEEP DUTTA
Tera Patron
Tera Patron

Hi @Deepa12 ,

Your Question is not clear, can you provide more details please .

 

Thanks,
Sandeep Dutta

Please mark the answer correct & Helpful, if i could help you.

Thanks for reply, I am listing error messages into Issues column through Business Rule. the values listing like "User Name must be mandatory. Invalid Email address. please update location detail."  please advise business rule script to print the values like 

User Name must be mandatory.

Invalid Email address.

please update location detail.

 

Hi @Deepa12 ,

You can use /n or <br> in the sentence.

"User Name must be mandatory.<br>Invalid Email address.<br>please update location detail."

Hi @Deepa12, I would do this with the following solution:

// ES6+

let errorMessageText = "User Name must be mandatory. Invalid Email address. please update location detail.";
// Split the text on each dot characters
let errorMessages = errorMessageText.split(".");
// Remove the unnecessary white spaces and join using the line-break character
let errorMessagesInSeparatedLines = errorMessages.map(x => x.trim()).join(".\r\n");
gs.info(errorMessagesInSeparatedLines);

// ES5
var errorMessageText = "User Name must be mandatory. Invalid Email address. please update location detail.";
// Split the text on each dot characters
var errorMessages = errorMessageText.split(".");
// Remove the unnecessary white spaces and join using the line-break character
var errorMessagesInSeparatedLines = errorMessages.map(function(x) { return x.trim()}).join(".\r\n");
gs.info(errorMessagesInSeparatedLines);