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
Mega Sage
Mega 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();

 

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

2 REPLIES 2

AnubhavRitolia
Mega Sage
Mega 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();

 

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

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();