- 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 11:58 PM
Thanks for your suggestion.
Actually "KOK - SIDK - " is static but the other text will be dynamic. so I want to remove the text "KOK - SIDK - " from short description whenever a ticket will be created from catalog.
Short description is based on the selected options via catalog so most of the text is dynamic but only this "KOK - SIDK - " is static. so I want to remove it.
my code is able to remove "KOK - SIDK" but not space & -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 12:17 AM - edited 09-19-2024 12:17 AM
Hi @ArunG29061990,
You can make the below changes to test in the background scripts, its working fine for me :
var gr = new GlideRecord("sys_req_item");
gr.addQuery("number","");//give the ritm number which has the desired description
gr.query();
if(gr.next()){
var desc = gr.short_description;
var j = "KOK - SIDK - ";
if (desc.includes(j)) {
//gs.print("hi");
desc = desc.replace(j, "").trim();
gs.print(desc);
}
}
If you get any error, please feel free to attach the error screenshot.
Please mark this solution "Helpful" if this answer helped you in any way.
Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 02:48 AM
tried this code as well but the problem is var is not considering the value - so we need to check how var can consider this - (hyphen) as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 04:47 AM
@ArunG29061990 Please try below updated script.
current.short_description += producer.Issue_Category + " - " + "Tenant: " + producer.getDisplayValue("cmdb_ci");
// Define the exact string to remove
var prefixToRemove = "KOK - SIDK - ";
// Check if the short description contains the string and replace it
if (current.short_description.includes(prefixToRemove)) {
current.short_description = current.short_description.replace(prefixToRemove, '').trim();
}