Switch Syntax for populating Catalog Task Short Desc from Workflow

jlaps
Kilo Sage

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!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jlaps 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

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.

 

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){

jlaps_0-1742569832344.pngjlaps_1-1742569887377.png

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.

Ankur Bawiskar
Tera Patron
Tera Patron

@jlaps 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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.