- 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-19-2024 02:45 AM
As you can see from my screenshot, it works totally fine.
The configuration item is KOK - SIDK - ServiceProvider, and the part "KOK - SIDK - " has been removed from the short description.
Can you verify the name of your CI to see is there any mismatch with the hyphen and the en dash? Sample: "–" and "-"
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 03:11 AM - edited 09-19-2024 03:13 AM
CI Name is : KOK SIDK - <name of company>
I have checked that only this hyphen (-) is creating problem if use "KOK SIDK - ABC" in code then it will remove the whole name but if I use only "KOK SIDK -" it's not removing anything.
so this hyphen is creating issue.
- 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-19-2024 04:38 AM
Well @Tai Vu
I tried "KOK SIDK -". multiple times but it's not working in my code. Not sure why.
Yes CI name contains the company name but it's not auto-generated we have predefined CMDB for all company names like
"KOK SIDK - <companya>
"KOK SIDK - <companyb>
"KOK SIDK - <companyc>
so on
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 10:31 PM
Hi @ArunG29061990 ,
I have tried the below script in the background script and was successfully able to remove the space and - from the short description. Please find the script below:
var desc = "Configuration Incident Response Team - P2P - AnyERP Task - High Memory/CPU - Tenant: KOK - SIDK - ServiceProvider";
var j = "KOK - SIDK - ServiceProvider";
if (desc.includes(j)) {
gs.print("hi");
desc = desc.replace(j, "ServiceProvider").trim();
gs.print(desc);
variable "j" is the one which was supposed to be replaced with "ServiceProvider" term so if that was available in the description variable all we had to do is to replace and trim any extra spaces.
Please mark this solution "Helpful" if this answer helped you in any way.
Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India