Script HELP on outgoing connection

Post Reply
rhd_ole
Member
Posts: 103
Joined: Mon Jan 24, 2022 5:36 pm

Script HELP on outgoing connection

Post by rhd_ole »

Hello,

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 :D :D

I was trying to use the job.SendTo() but I don't think that is the way so I have it

Current Code:

Code: Select all

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;
    }
  }
  
  if (isTrue) {
	  job.sendTo(True);
  } else if (isFalse) {
	  job.sendTo(False);
  }
}
Current setup in SwtichScripter.
Screenshot 2023-04-19 at 9.32.58 AM copy.jpg
Screenshot 2023-04-19 at 9.32.58 AM copy.jpg (231.77 KiB) Viewed 13612 times
Color Science & Workflow Automation
mkayyyy
Member
Posts: 79
Joined: Mon Nov 21, 2016 6:31 pm
Location: UK

Re: Script HELP on outgoing connection

Post by mkayyyy »

To send the jobs to an Outgoing connection that has a certain name you'd need to implement some logic like this:

Code: Select all

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());
	  }
  }
}
rhd_ole
Member
Posts: 103
Joined: Mon Jan 24, 2022 5:36 pm

Re: Script HELP on outgoing connection

Post by rhd_ole »

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:

Code: Select all

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.
Color Science & Workflow Automation
mkayyyy
Member
Posts: 79
Joined: Mon Nov 21, 2016 6:31 pm
Location: UK

Re: Script HELP on outgoing connection

Post by mkayyyy »

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
Post Reply