How to remove the whitespace business rule

Mrman
Tera Guru

Hi ,

I have created a business rule to replace a line in the Description field with empty space . 

It is working and that line is replaced with blank space . Now I want to remove this white space and move Up the line below it .

Please guide how to achieve it .

find_real_file.png

1 ACCEPTED SOLUTION

@ramamr 

I just used the same script and it worked fine for me

Original Message

find_real_file.png

Script:

var gr = new GlideRecord('problem');
gr.get('a463aa81db41e010224a2a9a48961954');

var desc = gr.description;
gs.info('Original String->\n' + desc);

desc = desc.replace(/Legal Entity Code: LE-[A-Z]+[\d]{3}/g, '');

var arr = desc.replace(/(\r\n|\n|\r)/gm, "@").replaceAll('@',',').split(',');
var finalArr = [];
for(var i in arr){
if(arr[i] != ''){
finalArr.push(arr[i].toString());
}
}

var finalString = finalArr.join('\n');

gs.info('Final String->\n' + finalString);

gr.description = finalString;
gr.update();

find_real_file.png

find_real_file.png

Regards
Ankur

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

View solution in original post

19 REPLIES 19

Mike Patel
Tera Sage

share business rule script you have.

Attaching screenshot also with white space after this BR ran.

I want to move the line below white space above .

@ramamr 

You can use this logic

var description = current.description.toString();



    if (description.includes('Legal Entity Code: LE-')) {

        var grdesc = new GlideRecord('sn_hr_core_case');
        grdesc.addEncodedQuery('active=true^descriptionLIKELegal Entity Code: LE-');
        grdesc.addQuery('sys_id', current.sys_id);
        grdesc.orderByDesc('sys_created_on');
        grdesc.setLimit(1);
        grdesc.query();

        if (grdesc.next()) {
        var finalArr = [];
        var value = description.replace(/Legal Entity Code: LE-[A-Z]+[\d]{3}/g, '');
        var arr = value.toString().split('\r\n');
        for(var i=0;i<arr.length;i++){
        if(arr[i].trim() != ''){
        finalArr.push(arr[i].toString());
        }
        }
            grdesc.description = finalArr.toString();
            grdesc.update();
        }

    }

})(current, previous);

Regards
Ankur

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

@ramamr 

please check the script I shared

Regards
Ankur

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