- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 06:46 AM
The final wording of my short description text is not working, and I was hoping for some guidance on where I am going wrong with it
// Set values for the task in this script. Use the variable 'task' when setting additional values.
// Note: This script is run after the task values are set using the Fields, Template or Values you have specified.
//
// For example:
var type = '';
var dept = current.variables.department;
switch (dept){
case "bid_strategy":
type = current.variables.bid_strategy_type.getDisplayValue();
break;
case "commercial":
type = current.variables.commercial_request_type.getDisplayValue();
break;
case "contracts":
type = current.variables.contracts_request_type.getDisplayValue();
break;
case "executive":
type = current.variables.executive_request_type.getDisplayValue();
break;
case "fps":
type = current.variables.fps_request_type.getDisplayValue();
break;
case "marketing":
type = current.variables.marketing_request_type.getDisplayValue();
break;
case "pricing":
type = current.variables.pricing_request_type.getDisplayValue();
}
task.short_description = "RevOps Support Request - "+current.variables.requested_for.name +" - "+current.variables.department.getDisplayValue() +" - "+type;
The +type at the end is not working, and just coming back blank. What am I doing wrong, and what is the best way to fix? Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2025 08:21 AM
try this
switch (dept + ''){
OR
use this
var dept = current.variables.department.toString();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 07:06 AM
Hi @jlaps ,
The variable type is totally dependent on the variable dept.
Kindly check what value you are getting in the variable dept. If dept is blank, it will not enter the switch block.
try making below changes
var dept = current.variables.department.getDisplayValue();
Mark this helpful/ Accept the solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2025 08:15 AM
I added a log statement right before the CASE, and it seems to be providing what I am looking for-
var type = '';
var dept = current.variables.department;
gs.info("JAL Revops - "+dept);
switch (dept){
But the task short description is still missing what 'type' should be set to in the case. If I changed the var dept assignment as you note, I would just have to change the case checks against the display value, but it seems to be working based on the value as it stands... unless I am not understanding something.
Added another log statement within the case-
case "bid_strategy":
type = current.variables.bid_strategy_type.getDisplayValue();
gs.info("JAL Revops - "+type);
break;
But as you suspected, it appears to not actually get into the case as this statement did not log.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2025 08:21 AM
try this
switch (dept + ''){
OR
use this
var dept = current.variables.department.toString();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2025 08:25 AM
Ok, adding the
(dept + '')
Worked. I am very curious as to WHY though, if you can explain it :). It looks like we are adding nothing to dept, and yet it needs that nothing somehow.