comparing two context variables on service node

In my service node,I am trying to compare two context variables.
One variable is from the response of service node and another is from other service node.

When I compare hard coded value with context it works well, but when I am using another context variable with {{}} , it is not working.

Is there another way to do it.

if (context.getPersonInternalID.response.body.fullName
equals to
{{context.getProject.response.body.manager.displayValue}}
then go to
another node

Hi @sharvari4810c,

Currently, the provision to compare two context variables in “condition rules” of a node is not available due to few technical limitations.

As of now, you can have a script node to compare the two context variables and return true or false as per the comparison.

Then, in the “condition rules” of the script node, you can navigate to other nodes if the context.scriptNode value is equal to “true”.

image

Let us know if you need any further clarification on the above.

Regards,
Yoga Ramya.

Thanks for this. Can you also show the underlying JS? I’m trying to apply but not getting true

@trevor.brown,

The underlying JS in the script node is a pure javascript “if” and “else” conditions that checks the values based on the context variables.

Please re-check your javascript syntax and let us know.

Regards,
Yoga Ramya.

This is what I have so far. I’ve tried it a few ways. You can see I commented out the return.

var variable_1 = “test”;
var variable_2 = “test”;
var validateUserId = false;

if(variable_1 == variable_2){
validateUserId = true;
   // return validateUserId;
}

Pretty basic JS here. Does this look like it would evaluate to true correctly.

var variable_1 = “test”;
var variable_2 = “test”;
var validateUserId = false;

if(variable_1 == variable_2){
validateUserId = true;
   // return validateUserId;
}

Hi @trevor.brown,

Please find the below implementation of the working model.

We have added the following script in the script node:

var var1 = “test”;
var var2 = “test2”;
context.returnVal = “false”;

if(var1 === var2){

context.returnVal = “true”;

}else{
context.returnVal = “false”;
}
return context.returnVal;

image

In the connection rules, we have setup connections as per the below screenshot

image

Kindly refer the above and let us know if you are unable to proceed further.

Regards,
Yoga Ramya.

image

Good morning,
Thanks,
I updated as instructed and now I get an error.

“I am sorry but something went wrong and I had to discard your task”

Question does the variable returnVal have to be declared somewhere other than within the script?

Trev

@trevor.brown,

The variable returnVal need not be declared anywhere else except the script node.
We request you to re-check and implement as the same code is working as expected at our end.

This could probably be a syntax error in the script node. Please re-check.

Regards,
Yoga Ramya.

The error is
Invalid or unexpected token.

Have no idea why that error message is being displayed for simple javascript

Here are few changes you can do

image

It worked for me