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

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

Hi Ankur,

Please let me know is there any different approach instead of splitting by (.).