I am working on a Cognex In-Sight program and having some trouble when using Javascript to switch recipes.
we are having a problem where we have a text field that is read and chooses a recipe based on what is entered. The problem is whenever that recipe changes the string in the text field is disabled.
To fix this I am trying to write the string entered in a text box to a variable, wait until a recipe changes and then write that variable back into the text box
Here is the code I am currently trying:
const aql = ['AQL17012', 'AQL17016', 'AQL33024' , 'AQL17112' , 'AQL17116' , 'AQL33124'];
const aqlHT = ['AQL17012HT', 'AQL17016HT', 'AQL33024HT'];
const aqxB = ['AQX17012', 'AQX17016', 'AQX33024'];
const aqxI = ['AQX22012', 'AQX22016', 'AQX44024'];
const aqxBHT = ['AQX17012HT', 'AQX17016HT', 'AQX33024HT'];
const aqxIHT = ['AQX22012HT', 'AQX22016HT', 'AQX44024HT'];
var textBox = $WebPages.HMI.CurrentPartTextB.Text
if ( aql.includes($WebPages.HMI.CurrentPartTextB.Text) === true) {
$System.Recipes.Products.Load('AQL');
$WebPages.HMI.CurrentPartTextB.Text = textBox
} else if ( aqlHT.includes($WebPages.HMI.CurrentPartTextB.Text) === true) {
$System.Recipes.Products.Load('AQLHT');
$WebPages.HMI.CurrentPartTextB.Text = textBox
} else if ( aqxB.includes($WebPages.HMI.CurrentPartTextB.Text) === true) {
$System.Recipes.Products.Load('AQX BODY');
$WebPages.HMI.CurrentPartTextB.Text = textBox
} else if ( aqxI.includes($WebPages.HMI.CurrentPartTextB.Text) === true) {
$System.Recipes.Products.Load('AQX INS');
$WebPages.HMI.CurrentPartTextB.Text = textBox
} else if ( aqxBHT.includes($WebPages.HMI.CurrentPartTextB.Text) === true) {
$System.Recipes.Products.Load('AQXHT BODY');
$WebPages.HMI.CurrentPartTextB.Text = textBox
} else if ( aqxIHT.includes($WebPages.HMI.CurrentPartTextB.Text) === true) {
$System.Recipes.Products.Load('AQXHT INS');
$WebPages.HMI.CurrentPartTextB.Text = textBox
}
I am using the dictionaries at the top to determine which string changes to which job. Then I am trying to assign the string in the text box to the 'var textBox', so when the recipe changes it can change the text field back to the string stored in var textBox.
The recipe switching side of the code works fine, I just can't figure out a way to repost the string back into the text box after the recipe changes
New to javascript so any help would be appreciated!