Velocity template in define varaiable in workflow

Hi team,
does anyone has tried to provide the velocity template as the varaiable in the define variable operator in workflows. Is there any possibility for it.


when I tried I am getting not a valid json
the expression I used is as follows
#if({{$.trigger.stafftype}}==‘N’)fd4708bf2dcd49ddb5e0c241a9c30438 #elseif (!{{$.trigger.stafftype}}==‘N’ && !{{$.trigger.studenttype}}==‘N’)fd4708bf2dcd49ddb5e0c241a9c564438#{else}e5d708bf2dcd49ddb5e0c241a9c30438#end

I need this varaiable to store the sourceid where depending on the trigger input I want to create account in the three different sources.
but I want to minimize it by writing only one create account step where the source id will be from the define varaiable step.

Hope I will find my solution, Thanks in advance

Hi,

Velocity Templating is not supported in ISC Workflow. Instead what you can do is use “Compare String” action to compare if sourceId is equal too source1 then do the action you want and if false, add another “Compare String”. This would create a if-else ladder and you can define your workflow action in there.

Regards,
Animesh Tarodia

As you mentioned you need only one “Create Account” operation then in each ladder use define Variable to store the sourceId, name each variable as “x” in the Define Variable action and frame the JSONPath expression as “$[‘defineVariable’,‘defineVariable1’,‘defineVariable2’].x”. This way it outputs only the non-null value.

2 Likes

Thanks Animesh, can we use velocity template in the http request body is there any possibilty for that.

No, only JSONPath expressions are allowed.

Ok, Thanks. I will try the above approach.

2 Likes

Do I need to use the expression at the sourceid field in the create account http request

In defineVariable, you would define the sourceIds and when you would use $[‘defineVariable’,‘defineVariable1’,‘defineVariable2’].x, this will directly get you the intended sourceId to use in sourceId field.


i have defined three define varaiables in the same format
In the create account if I given this expression
image
I am getting invalid json

if u don’t mind can u just post the json for this workflow

I think you are just missing curly braces. Try using {{ $[‘defineVariable’,‘defineVariable1’,‘defineVariable2’].x}}

1 Like

I have added them to still getting the same error

Can you share your json payload?

{“attributes”:{“email”:“{{$.trigger.email}}”,
“sourceId”:“{{$[‘defineVariable1’,‘defineVariable3’,‘defineVariable2’].x}}”,
“username”:“{{$.trigger.name}}”,“userpassword”:“{{$.trigger.password}}”}}

ok its working fine I have used curly quotes instead of straight quotes

1 Like

I was able to reproduce the issue. I added another Define Variable action and referenced that variable in my http request and that produced the intended json response.

			"Define Variable 3": {
				"attributes": {
					"id": "sp:define-variable",
					"variables": [
						{
							"description": "",
							"name": "sourceId",
							"transforms": [
								{
									"id": "sp:transform:trim:string",
									"input": {
										"postfix": true,
										"prefix": true
									}
								}
							],
							"variableA.$": "$['defineVariable','defineVariable1','defineVariable2'].x"
						}
					]
				},
				"displayName": "",
				"nextStep": "HTTP Request 1",
				"type": "Mutation"
			},

Here’s the JSON I used for HTTP Request,

{
  "attributes": {
    "email": "{{$.trigger.email}}",
    "sourceId": "{{$.defineVariable3.sourceId}}",
    "username": "{{$.trigger.name}}",
    "userpassword": "{{$.trigger.password}}"
  }
}

Thanks for ur efforts, I will work on it.

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.