I'm new to using the SwitchScripter and I'm trying to create a script that will allow the user to input to numbers and select a comparison of ">" or "<"
and send the result to the connection that has the outgoing connection property of "True" to one connection and "False" to the other connection based on the result - Again excuse my newness
I was trying to use the job.SendTo() but I don't think that is the way so I have it
mkayyyy wrote: ↑Thu Apr 20, 2023 4:14 pm
To send the jobs to an Outgoing connection that has a certain name you'd need to implement some logic like this:
function jobArrived(s: Switch, job: Job) {
var privateData = s.getPropertyValue("EntryNumber");
var compareNumber = s.getPropertyValue("CompareNumber");
var comparison = s.getPropertyValue("Comparison");
var isTrue = false;
var isFalse = false;
if (comparison === "<") {
if (parseInt(privateData) < parseInt(compareNumber)) {
isTrue = true;
} else {
isFalse = true;
}
} else if (comparison === ">") {
if (parseInt(privateData) > parseInt(compareNumber)) {
isTrue = true;
} else {
isFalse = true;
}
} else if (comparison === "=") {
if (parseInt(privateData) === parseInt(compareNumber)) {
isTrue = true;
} else {
isFalse = true;
}
}
var connections = s.getOutConnections();
var trueConnection, falseConnection;
if (connections.length > 0) {
for (var i = 0; i < connections.length; i++) {
var currentConnection = connections.getItem(i)
if (currentConnection.getName() === "True") {
trueConnection = currentConnection;
}
else {
falseConnection = currentConnection;
}
}
if (isTrue) {
job.sendTo(trueConnection, job.getPath());
} else if (isFalse) {
job.sendTo(falseConnection, job.getPath());
}
}
}
Thank you. This definitely helps.. Seems best to leave them generic. I do want to be able to select on the outgoing connection of True or False and use that to route them unless you feel it should be done a different way via Traffic light or similar? Just trying to figure out best practices.
I'd recommend using traffic light connections either that or have a single outgoing connection and set a true/false value as private data which you can evaluate further down the flow