- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 08:10 PM
Hi,
I was modifying one catalog where I need to manipulate the short description.
My short description was "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 already removed this KOK - SIDK with the help of community by adding the below-given code:
current.short_description += producer.Issue_Category + " - " + "Tenant: " + producer.getDisplayValue("cmdb_ci");
var prefixToRemove = "KOK - SIDK";
if (current.short_description.includes(prefixToRemove))
{ current.short_description = current.short_description.replace(prefixToRemove,'').trim(); }
but this code is not removing space & - from the short description so tried this:
var prefixToRemove = "KOK - SIDK - ";
after adding "space -" in var, it's breaking the whole code and it's not even removing "KOK - SIDK".
So can you please suggest how to remove "Space -" along with "KOK - SIDK" from the short description of catalog with the same code?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 03:40 AM
CI Name is : KOK SIDK - <name of company>
Then the prefix variable should be "KOK SIDK -". You can replace the prefix from my script to match with your case.
var prefixToRemove = "KOK SIDK - "; //prefix
Also, I see you mentioned that CI name contains the company name? is the CI name is auto-generated in your case? If yes you can query the CI to retrieve the Company name for the short description instead of trying to remove a part of the CI name.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 09:52 PM
I'm not so sure about the business need, are you building a fix script to do a bulk updates for short description where you expect the "KOK - SIDK - " to be removed? it would be great if you elaborate more about it.
In regards to the script to replace a specific text, you can leverage the replace() or replaceAll() method.
Sample.
var short_description = "Configuration Incident Response Team - P2P - AnyERP Task - High Memory/CPU - Tenant: KOK - SIDK - ServiceProvider";
var prefixToRemove = "KOK - SIDK - ";
short_description = short_description.replace(prefixToRemove, '');
gs.info(short_description);
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 11:54 PM
Hi @Tai Vu
Thanks for your quick reply.
We are creating incidents from defined catalogs so the short description will be changed for every ticket.
Configuration Incident Response Team - P2P - AnyERP Task - High Memory/CPU - Tenant: KOK - SIDK - ServiceProvider"
RED is the first part of short description that will change according to the selected value while creating the incident.
GREEN is the second part where "KOK - SIDK -" is the prefix for every tenant that I need to remove from short description. so at the end of short description only Tenant: ServiceProvider (ServiceProvider will also change)
I am using the below-given code and it's removing "KOK - SIDK" from the second part of description but I would need to remove space & - as well so that only Tenant: <Name> that will be shown.
current.short_description += producer.Issue_Category + " - " + "Tenant: " + producer.getDisplayValue("cmdb_ci");
var prefixToRemove = "KOK - SIDK";
if (current.short_description.includes(prefixToRemove))
{ current.short_description = current.short_description.replace(prefixToRemove,'').trim(); }
I used the below-given var as well but it's not working. so is there any way if I can remove space & - from the short description along with "KOK - SIDK"?
var prefixToRemove = "KOK - SIDK - ";
Even when I add space & - in the var, it stopped to remove "KOK - SIDK" as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 12:26 AM
Let give my script a try. I did a quick test in PDI, it works well from my end.
var prefixToRemove = "KOK - SIDK - "; //prefix
var tenantCI = producer.getDisplayValue("cmdb_ci"); //tenant CI
tenantCI = tenantCI.replace(prefixToRemove, ''); //remove prefix
var short_description = producer.Issue_Category + " - " + "Tenant: " + tenantCI; //build short description
current.short_description = short_description.trim(); //set short description
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 02:27 AM - edited 09-19-2024 02:47 AM
@Tai Vu :
this code is also not working for space & -.
so the code is able to remove KOK SIDK only not -
Working with "KOK SIDK";
Not working with "KON - SIDK -";
Please note this ServiceProvider is a dynamic value and this will be shown as per the selection of tenant name.
Actually the problem is var is not considering the value - so we need to check how var can consider this - (hyphen) as well.
Tenant Names are : KOK SIDK - <abcetc>
so in short description, we just want to show that abcetc value and this tenant value is coming from "producer.getDisplayValue("cmdb_ci")" this table.