How can I get rid of blank spaces when using inline expressions inside the Description field of a Catalog Item template?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 07:44 AM
For some reason I get this blank spaces in between the Building and the Floor inline expressions.
I tried appending trim() to the end of the field name inside the expression, but it did nothing. I also checked for surround spaces before and after each one of them, and they are all the same.
It looks like the building.name field is an object with multiple properties where some of them are empty. I tried multiple addresses to no avail.
-------------------------------------------------------------------
Building: ${employee_sys_id.building.name.trim()} Floor: ${employee_sys_id.building.u_floor.trim()}
-------------------------------------------------------------------
Please see sample screenshot below
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 07:56 AM
Hi,
check what is the value in the building field; if it is with newline characters and only 1 line exists then possibly blank space is coming
you can use email script to handle this and check any new line character is present or not
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2020 05:47 AM
Thanks Ankur for replying.
I apologize for not getting back to you sooner, but I was tied up with a different project for the last couple of days.
I checked the 'name' field in the sys_building table, and it looks fine, with a max. length off 100 chars. Thing is that sometimes the space gap disappears depending on the employee_sys_id used.
I am a junior ServiceNow developer with not much JavaScript experience, but I was thinking I could use the trim() function inside the inline expression to remove extra spaces from the sys_building.name field. The trim() function itself does not return any sintax error, but it does not seem to trim the space in this case. As a test, I temporarily removed the below expression from the template Description field, and the space gap disappeared, meaning the issue is caused by extra spaces in that particular field.
Building: ${employee_sys_id.building.name.trim()}
Thanks a lot for your input.
Juan Guzman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2020 06:40 AM
Hi,
So are you saying using below line of code the extra spaces in the name field got disappeared?
Building: ${employee_sys_id.building.name.trim()}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader