The CreatorCon Call for Content is officially open! Get started here.

Populating a String field with another string field but with some restriction

Lavanya Nagendr
Giga Guru

Hi All,

 

I have a requirement where i need to get the "Descripion" field and auto populate another field lets say."Description 1" but without any numbers.

 

For example:

 

if Description ----is--> General Requirement 1.1

then Description 1 ---should be---> General Requirement

 

Note: The content on the Description may vary and the numbers like(1.1 or 1.04) will always be at the end.

1 ACCEPTED SOLUTION

Hi @Lavanya Nagendr 

 

You can put like below

 

var description = "General Requirement 1.1  @%";

description = description.replace(/[0-9.]/g, '');

var description_1= description;
Regex explaination :
0-9 - check numbers
.      - check dot(.)
/g  - search entire string
 
You can use /[0-9.@#$%^]/g if you have special characters as well
 
Output : 
 
VishalBirajdar7_0-1694777022537.png

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

6 REPLIES 6

Vishal Birajdar
Giga Sage

Hi @Lavanya Nagendr 

 

You can use replace function

 

var description = "Servicenow 123 hello world 232 g 4";

description = description.replace(/[0-9]/g, '');   //replace with empty string

var description_1 = description;

 gs.info(description_1);

 

Output :

 

VishalBirajdar7_0-1694775142898.png

 

for replacing any other characters you need to update regex.

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hi @Vishal Birajdar ,

 

Its working but the result i got for 

 

var description = "General Requirement 1.1";
description = description.replace(/[0-9]/g, '');
 description 1= description;

 

 

General Requirement 1.1

 

Output: 

General Requirement .

 

Hi @Lavanya Nagendr 

 

You can put like below

 

var description = "General Requirement 1.1  @%";

description = description.replace(/[0-9.]/g, '');

var description_1= description;
Regex explaination :
0-9 - check numbers
.      - check dot(.)
/g  - search entire string
 
You can use /[0-9.@#$%^]/g if you have special characters as well
 
Output : 
 
VishalBirajdar7_0-1694777022537.png

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

It worked!

@Vishal Birajdar  Thanks for helping me out! 🙂