ServiceNow Catalog - Short Description Manipulation

ArunG29061990
Tera Expert

Hi, 

 

I am modifying one catalog where I need to manipulate the short description. 

 

My current short description is like "Configuration Incident Response Team - P2P - AnyERP Task - High Memory/CPU - Tenant: KOK - SIDK - ServiceProvider"

 

but my requirement is "Configuration Incident Response Team - P2P - AnyERP Task - High Memory/CPU - Tenant: ServiceProvider"

 

So I want to remove this KOK - SIDK from every ticket. 

 

So basically this "KOK - SIDK" is a prefix for each and every tenant but we don't want it in short discription. So how to remove this?

 

Current code is :

current.short_description += producer.Issue_Category + " - " + "Tenant: " + producer.getDisplayValue("cmdb_ci");
 
and that tenant value is coming from " producer.getDisplayValue("cmdb_ci");" 
 
2 ACCEPTED SOLUTIONS

Eshwar Reddy
Kilo Sage

Hi @ArunG29061990 

To remove the prefix "KOK - SIDK" from the short description, add the following code immediately after the line:

// current.short_description += producer.Issue_Category + " - " + "Tenant: " + producer.getDisplayValue("cmdb_ci");

 

Insert this code

 

var prefixToRemove = "KOK - SIDK";
if (currentShortDescription.includes(prefixToRemove))
{
currentShortDescription = currentShortDescription.replace(prefixToRemove, '').trim(); // Remove the prefix and trim whitespace
}

Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

okay @Eshwar Reddy 

 

I just made a few changes:

 

var prefixToRemove = "KOK - SIDK";
if (current.short_description.includes(prefixToRemove))
{ current.short_description = current.short_description.replace(prefixToRemove,'').trim(); }
 
It works 🙂
 
Thanks @Eshwar Reddy 

View solution in original post

10 REPLIES 10

@ArunG29061990 
Cool
my pleasure

Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution



@Eshwar Reddy  one quick thing:

 

can we remove " - " (with space) from ServiceProvider as well? 

- ServiceProvider

@ArunG29061990 
Yes it is possible just update prefixToRemove

var prefixToRemove = "KOK - SIDK - ";
 
Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution

yeah, I tried the same (var prefixToRemove = "KOK - SIDK - "😉 but it breaks the code. 

 

after adding this it even stopped removing KOK - SIDK

 

so now the result is showing like
Configuration Incident Response Team - P2P - AnyERP Task - High Memory/CPU - Tenant: - ServiceProvider

@Eshwar Reddy the main problem is var is not considering the value - so we need to check how var can consider this - (hyphen) as well.