Remove first character from a table's field

AEterni
Mega Guru

Hello Team,

 

  • We have a custom table with some fields
  • One of these fields is called ""DL Name"
  • As per our naming convention the name of our DLs (Distribution Lists) must start with the special character "_"
  • We found out via ServiceNow support that the special character "_" breaks the flow action "for each"
  • We want to create a new field which takes a string in the "DL Name" field and removes the special character "_"

Is there an easy way to do it?

 

Thank you.

1 ACCEPTED SOLUTION

anubhavritolia
Giga Sage

Hi @AEterni 

 

You can create a Business Rule After Update with below condition:

DL Name is not empty

AND

DL Name changes

 

Code:

var str = current.u_dl_name.toString();
var newDLName = str.substring(1);

current.u_new_dl_name = newDLName; // u_new_dl_name is new field name which may vary based upon the field you create
current.update();

 

 

 

View solution in original post

2 REPLIES 2

anubhavritolia
Giga Sage

Hi @AEterni 

 

You can create a Business Rule After Update with below condition:

DL Name is not empty

AND

DL Name changes

 

Code:

var str = current.u_dl_name.toString();
var newDLName = str.substring(1);

current.u_new_dl_name = newDLName; // u_new_dl_name is new field name which may vary based upon the field you create
current.update();

 

 

 

latroyamitchell
Tera Contributor

Very helpful article!  The .substring(#) method can be used to remove character from the beginning of a string.  I used it in my business rule below. Hope this helps the next as well!

 

var label = current.name;

current.name = label.substring(5);
current.update();