Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

@jlaps 

current.variables.department doesn't give you string, so adding that '' makes that object as string and then it can be compared in switch

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