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

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

Thanks @Eshwar Reddy for the quick response.

 

I tried with the same code but it's not removing "KOK - SIDK" from the short description. Any idea?

Hi @ArunG29061990 
Just Ran the BS. it working as expected.
Please refer to the below screen shot.

EshwarReddy_0-1726665378012.png

Result

EshwarReddy_1-1726665397277.png

 

Try below code 

var prefixToRemove = "KOK - SIDK";
var pv = producer.getDisplayValue("cmdb_ci");
if (pv.includes(prefixToRemove))
{
pv = pv.replace(prefixToRemove, '').trim();
}



current.short_description += producer.Issue_Category + " - " + "Tenant: " + pv;

 

 

 

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