How do I conditionnaly run a query from text in an input widget?

Good day everyone !

Can I conditionally run a query from text in an input query ?
I have an input widget call flash and two queries transport 1 and transport 2

what i want to do is if the user writes a flash >= 145 run transport 1 else runs transport 2
I tried below but didn’t worked any help is appreciated .

export default {
myFun1: () => {
if(Flash.text >= “145”){
Transport1.run();
storeValue(“Transport”);
}
else{
Transport2.run();
storeValue(“Transport”);
}
},
}

Hello! The syntax for the storeValue() method is incorrect; it has at least 2 parameters. Can you elaborate on what you are trying to achieve with it? Please check our documentation on how to use storeValue().
Also, where are you running this JS function?

export default {
	myFun1: () => {
		if(Flash.text >= "145"){
			Transport1.run();
			storeValue("Transport",Transport1.data);
		}
		else{
			Transport2.run();
			storeValue("Transport",Transport2.data);
		}
	},
}

Hi Amelia , I fixed the syntax adding the second parameter. I am not sure what is that you are asking on where I am running the JS function ? . It is a new create Js Object . This will be part of a chain of querys in which in this step , the app should read the text in the input widget called flash and if it meets the criteria of being above 145 should run the first query and save the dataset as a storevalue .

Ok. Now to make this JS function run as expected, please use async/await. You will need to await the query run and the storeValue() method, because they are async functions.

export default {
	myFun1: async () => {
		if(Flash.text >= "145"){
			await Transport1.run();
			await storeValue("Transport",Transport1.data);
		}
		else{
			await Transport2.run();
			await storeValue("Transport",Transport2.data);
		}
	},
}

You can find more information on how to use async/await in our documentation about JS promises.

1 Like

Thank you so much , it worked like a charm and the documentation helped me to understand .