Using Assign Message, can we concatenate a string with a variable and assign the concatenated value to a new variable?

amar333n
Participant III

I achived this by using JS, I want to know whether I can achieve this using AssignMessage Policy.

Solved Solved
1 2 3,018
1 ACCEPTED SOLUTION

@Amar N

With the AssignMessage policy, and specifically within the AssignVariable element, you cannot use curly braces to represent a variable. You cannot use + or any other symbol as such to indicate you are concatenating the strings.

Anything that you specify in the <Value> will get assigned to variable as is, without de-referencing strings that may be surrounded by curlies.

You can use <Ref> tag to specify the name of an existing variable; in that case the value of that existing variable will be assigned to the new variable. Since you can't use curly braces here, if you try to concatenate another string with the variable, then you will end up with an error as it won't be able to resolve the variable.

In summary, you can't use AssignMessage/AssignVariable to concatenate a string with another variable and assign the new value to a variable. You can do this easily with a Javascript policy, which you seem to have already done.

In contrast, within the AssignMessage/Set/Payload element, YOU CAN use string concatenation and curly-braces and so on... to perform string concatenation .

Regards,

Amar

View solution in original post

2 REPLIES 2

@Amar N

With the AssignMessage policy, and specifically within the AssignVariable element, you cannot use curly braces to represent a variable. You cannot use + or any other symbol as such to indicate you are concatenating the strings.

Anything that you specify in the <Value> will get assigned to variable as is, without de-referencing strings that may be surrounded by curlies.

You can use <Ref> tag to specify the name of an existing variable; in that case the value of that existing variable will be assigned to the new variable. Since you can't use curly braces here, if you try to concatenate another string with the variable, then you will end up with an error as it won't be able to resolve the variable.

In summary, you can't use AssignMessage/AssignVariable to concatenate a string with another variable and assign the new value to a variable. You can do this easily with a Javascript policy, which you seem to have already done.

In contrast, within the AssignMessage/Set/Payload element, YOU CAN use string concatenation and curly-braces and so on... to perform string concatenation .

Regards,

Amar

Hi,

This is possible to concatenate with <template> element since the end of 2018.

View this post : https://community.apigee.com/answers/63462/view.html