With a Switch Workflow Activity, is it possible to have it look to see if the Description field contains a string as one of its conditions?

Scott Jordheim
Giga Guru

I currently have to use a lot of If statements to branch to various activities in the workflow, and using a switch to evaluate cases would be ideal, if possible. These items I have the If statements looking for are hard-coded from an external form.

 

For example:

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Hello Scott

Maybe with a Script Include you can evaluate.

Look at this:

I created a Script Include call GLOTest with a function conditionEvaluator

 

var GLOTest = Class.create();
GLOTest.prototype = {
	initialize: function() {
	},

	conditionEvaluator: function(condition,pattern)
	{
		if (condition == pattern) {
			return true;
		}
		else {
			return false;
		}
	},
	
	type: 'GLOTest'
};

 

In the condition of the switch option, call the Script Include like this

new GLOTest().conditionEvaluator('Hardware:true','Hardware:true');

 

find_real_file.png

The workflow result is true

 

find_real_file.png

The "logic" in the Script Include maybe is not the best solution, you can change the logic.

 

Ariel

PS: Please mark my answer correctly or helpful if I have helped you. Thanks

View solution in original post

4 REPLIES 4

arielgritti
Mega Sage

Hello

Maybe this can help you.

I think the condition must be somethig like this:

activity.result == 'Hardware Request Information'

 

Ariel

PS: Please mark my answer correctly or helpful if I have helped you. Thanks

This would work, if that would be all my Description contained. When the email / form comes in, it could contain any number of characters, with that string potentially in multiple places.

(It is a custom web form with variables that transform to true / false exactly like how I showed above upon submission. Once inbound actions take place, they transform it into a generic requested item, with the variables and the true/false choices being listed in the Requested Item's description. The workflow would be looking for the variable's question / label and the true/false answer to it basically.)

When using only the activity.results == '' piece, it appeared to just look if the description matched exactly what was in the condition. Using something like activity.results'contains("hardware information: true")' generated an error.

I gave the statement a shot without that activity.results'' piece initially (using only contains("hardware information: true")), and it generated the same error.

I couldn't find much online with using a contains operator in that switch condition.

Hello Scott

Maybe with a Script Include you can evaluate.

Look at this:

I created a Script Include call GLOTest with a function conditionEvaluator

 

var GLOTest = Class.create();
GLOTest.prototype = {
	initialize: function() {
	},

	conditionEvaluator: function(condition,pattern)
	{
		if (condition == pattern) {
			return true;
		}
		else {
			return false;
		}
	},
	
	type: 'GLOTest'
};

 

In the condition of the switch option, call the Script Include like this

new GLOTest().conditionEvaluator('Hardware:true','Hardware:true');

 

find_real_file.png

The workflow result is true

 

find_real_file.png

The "logic" in the Script Include maybe is not the best solution, you can change the logic.

 

Ariel

PS: Please mark my answer correctly or helpful if I have helped you. Thanks

That worked perfectly. Thanks!

It looks so much better than 20 different If statements meshed around the canvas. Also much easier to update should we ever need to (don't have to trace different paths to see where everything goes). Ideal end goal is to create the form directly in ServiceNow, but until then, this helps tremendously.