How to add / prefix text to a text field which already has text in it (business rule)?

jas101
Tera Expert

Hi guys, we'd like to prefix text to the change request short description on save.

I figure we can use a business rule to do this but what I don't know is how I would go about scripting adding text when it will already have text in it. E.g. if field 'Region' has more than one value (or a ',' perhaps) add / prefix the word 'GLOBAL' to the front of the short description if it isn't add / prefix the relevant region e.g. 'EMEA' to the short description.

Many thanks for any help in advance.

8 REPLIES 8

Also how do I 'print' the Region(s) display name to add / prefix to Short description if...

if(region.length < 1) ?

Many thanks.

One option is to avoid the update checkbox. But you need it to run the business rule on updates as well. So you could just replace the script to

 

var region [] = current.u_region.split(",");  //Assuming region is a glide list and u_region is column name

var text = current.short_description;

if(region.length > 1 && text.indexOf("GLOBAL") < 0 ){

current.short_description  = "GLOBAL " + text ;

}

Also how do I 'print' the Region(s) display name to add / prefix to Short description if...

if(region.length < 1) i.e. it's not 'GLOBAL'?

Many thanks.

So this is more code 🙂

Try this out (NOT Tested)

var region [] = current.u_region.split(",");  //Assuming region is a glide list and u_region is column name

var text = current.short_description;

if(region.length > 1 && text.indexOf("GLOBAL") < 0 ){

current.short_description  = "GLOBAL " + text ;

}else if (region.length == 1){  //Single region

var location = new GlideRecord('cmn_location');

if(location.get(current.u_region.toString())){  //Replace with your column name

current.short_description  = location.name + " " +  text ;

}

}