Convert a script to use Traffic Light output

Post Reply
cwswitch
Member
Posts: 78
Joined: Fri Feb 24, 2017 12:25 am

Convert a script to use Traffic Light output

Post 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!
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Convert a script to use Traffic Light output

Post by jan_suhr »

Take a look here:
http://www.enfocus.com/manuals/Develope ... class.html

You will use the sendToData function
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
cwswitch
Member
Posts: 78
Joined: Fri Feb 24, 2017 12:25 am

Re: Convert a script to use Traffic Light output

Post 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);
User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Convert a script to use Traffic Light output

Post by gabrielp »

This script/app is an example of using traffic light connectors: https://github.com/open-automation/swit ... #L274-L280
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
cwswitch
Member
Posts: 78
Joined: Fri Feb 24, 2017 12:25 am

Re: Convert a script to use Traffic Light output

Post 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;
				
	}
User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Convert a script to use Traffic Light output

Post 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).
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
cwswitch
Member
Posts: 78
Joined: Fri Feb 24, 2017 12:25 am

Re: Convert a script to use Traffic Light output

Post by cwswitch »

Awesome thanks, you're very helpful
Post Reply