Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Extracting values from string

girishk
Tera Expert

Hi ,

I need to extract the last four digits of a number field ,irrespective of the identifiers. mean we dont have any option to split on the string like (" , _, -,) etc.just blindly need to extract last four characters of the string.how can we achieve this..

 

Regards,

Girish .K

1 ACCEPTED SOLUTION

Matthew Smith
Kilo Sage

Hi Girish

 

If you are in a client script you can use .slice(-4) to get the last 4 characters of a string. For an example, the below will alert the last 4 characters of the short description field when loading an incident.

function onLoad() {
var desc = g_form.getValue('short_description');
var lastFour = desc.slice(-4);
alert(lastFour);
}

 

Hope it helps.

 

Matt

View solution in original post

2 REPLIES 2

Matthew Smith
Kilo Sage

Hi Girish

 

If you are in a client script you can use .slice(-4) to get the last 4 characters of a string. For an example, the below will alert the last 4 characters of the short description field when loading an incident.

function onLoad() {
var desc = g_form.getValue('short_description');
var lastFour = desc.slice(-4);
alert(lastFour);
}

 

Hope it helps.

 

Matt

girishk
Tera Expert

Thanks Matt