Scripting a Variable in Integration hub

jonathangilbert
Mega Sage

Hello, 

I want to streamline flows by not having to create "If" actions and then "Set Flow Variable" for multiple catalog variables

What I wish to do is have one action to  "Set flow Variable", but then within that action set multiple variables using individual scripts for each one.

So in the example below I want to set the Flow Variable "3rd Party"  only if the submitted form variable "

which_3rd_party_do_you_work_for" is not empty.
flow variable.png
If the submitted form flow variable "which_3rd_party_do_you_work_for" is empty, then don't update the variable "3rd party".
 
This is the script I have built, but it doesn't work, it comes  back with "
"They work for the the 3rd party undefined", if the form variable is empty
 
var third  = fd_data._1__get_catalog_variables. which_3rd_party_do_you_work_for.name;
if (third != ""){
var result = "They work for the the 3rd party " + third;
return result;
}
if (third == ""){
var result1 = ""  
return result1
}
 
 
What am i missing?
1 ACCEPTED SOLUTION

Dinesh Chilaka
Kilo Sage

Hi @jonathangilbert ,

Try the below script,

var third  = fd_data._1__get_catalog_variables. which_3rd_party_do_you_work_for;
if(third){
return "They work for the the 3rd party "+fd_data._1__get_catalog_variables. which_3rd_party_do_you_work_for.name;
}
else{
return "";
}

If my response helped, mark it as helpful and accept the solution.

Thanks,

Dinesh

View solution in original post

4 REPLIES 4

Dinesh Chilaka
Kilo Sage

Hi @jonathangilbert ,

Try the below script,

var third  = fd_data._1__get_catalog_variables. which_3rd_party_do_you_work_for;
if(third){
return "They work for the the 3rd party "+fd_data._1__get_catalog_variables. which_3rd_party_do_you_work_for.name;
}
else{
return "";
}

If my response helped, mark it as helpful and accept the solution.

Thanks,

Dinesh

Shaik Dimple
Tera Guru

Hi @jonathangilbert 

 

What type of catalog variable is "which_3rd_party_do_you_work_for"? Is it a Reference, Select Box or Single Line Text variable?

The way we access the value can be different depending on the variable type.

 

Regards

Dimple Shaik

yashkamde
Giga Sage

Hello @jonathangilbert ,

 

May be when which_3rd_party_do_you_work_for is blank, (fd_data._1__get_catalog_variables.which_3rd_party_do_you_work_for.name) doesn't resolve to an empty string "", it resolves to the literal JavaScript value undefined.

and when you compare undefined != "", that evaluates to true, so your script falls into the has a value.

 

So try fixing the script :

var third = fd_data._1__get_catalog_variables.which_3rd_party_do_you_work_for.name;
var result = "";

if (third !== undefined && third !== null && third !== "") {
    result = "They work for the 3rd party " + third;
}

return result;

 

also try to print the value using Log Action.

 

If my response helped mark as helpful and accept the solution.

jonathangilbert
Mega Sage

HI Dinesh, this works perfectly , thankyou so much 🙂