Page 1 of 1

Convert a script to use Traffic Light output

Posted: Sun Jan 06, 2019 11:27 pm
by cwswitch
This is the area of Switch I have most to learn about.

I have a script made by a previous person and it can error. I think that having a traffic light output connector will help me move the problem jobs away from the good ones.

The script does throw an error (something like an undefined variable or a nullable object is not an instance of an object) so I'm hoping that is enough for it to get pushed down the Error Out connector - but it does not work.

What I did was make a copy of the old script and change the Outgoing Connection Type to Traffic Light

Any tips on what to try next as so far the jobs just hang in the folder before the script

Thanks!

Re: Convert a script to use Traffic Light output

Posted: Sun Jan 06, 2019 11:36 pm
by jan_suhr
Take a look here:
http://www.enfocus.com/manuals/Develope ... class.html

You will use the sendToData function

Re: Convert a script to use Traffic Light output

Posted: Mon Jan 07, 2019 12:19 am
by cwswitch
Ah brilliant, thanks.

So where the script is currently producing its error,

Code: Select all

throw new Error...;
Can I just add below

Code: Select all

sendToData(3);

Re: Convert a script to use Traffic Light output

Posted: Mon Jan 07, 2019 10:39 pm
by gabrielp
This script/app is an example of using traffic light connectors: https://github.com/open-automation/swit ... #L274-L280

Re: Convert a script to use Traffic Light output

Posted: Tue Jan 08, 2019 1:51 am
by cwswitch
Thanks Gabriel

your script appears so clean and readable, even though it is still way beyond me I can at least see how you handle your errors.

I have edited the script I had as below and it seems to work in a test. I'm very scared to put it into production though as I'm so inept at scripting.

OLD - Part one where it generates the error

Code: Select all

 
	try {
		job.sendToSingle(job.getPath());
	} catch (e) {
	
	}
NEW - My guess was to do this

Code: Select all

 
 	try {
		job.sendToData( 1, job.getPath() );
	} catch (e) {
	
	}


OLD - snip... after it sends a SOAP request and the error is returned it does this

Code: Select all

				if (resu !== "Success") {
					throw new Error("Invalid response from web service: " + resu);	
				}	
				return resu;
				
	}
NEW - My guess was to do this

Code: Select all

				if (resu !== "Success") {
					//throw new Error("Invalid response from web service: " + resu);	
					job.sendToData( 3, job.getPath() );
				}	
				return resu;
				
	}

Re: Convert a script to use Traffic Light output

Posted: Tue Jan 08, 2019 3:24 pm
by gabrielp
cwswitch wrote: Tue Jan 08, 2019 1:51 am NEW - My guess was to do this

Code: Select all

				if (resu !== "Success") {
					//throw new Error("Invalid response from web service: " + resu);	
					job.sendToData( 3, job.getPath() );
				}	
				return resu;
				
	}
Looks good to me, if what you want to do is, on SOAP error, move the input job into the error connector. Since I can't see the entire script and what ultimately happens to `resu`, I'll offer this suggestion. You likely still want to capture what you were capturing in this exception that was being thrown. Perhaps a log error. Traffic light also supports a log output as well if you wanted to capture the entire SOAP response as a file. This is kind of helpful in some cases (even in success) if you wanted to output an XML result (like the SOAP response) as a log which could be consumed as a dataset later. You can still use the data side of your traffic light for the job (whatever that is).

Re: Convert a script to use Traffic Light output

Posted: Tue Jan 08, 2019 11:02 pm
by cwswitch
Awesome thanks, you're very helpful