Script snap / load configuration file

In a javascript script pack is how do I load/read a file that is available in the manager?

I cant find an example showing how to read in external files inside a Script snap, or how to pass both an incoming doc and a configuration to the Script snap.

I have a generic validation script, that is going to be a child pipeline to many parents, so need to apply different criteria to validate incoming documents differently; eg. there may be a “loose” configuration, where an email just needs to contain @ and be length >1 and <1000, or a “strict” configuration, where a complex reg exp is applied, so the generic script remains the same, but reads in and applies validation via a configuration file.

I guess you are saying whether a Script snap can read a file from the manager. I am not sure, but you can read a file via File Reader and then convert that into a document using BinaryToDocument snap. All your file’s data will be there in the “content” field. You can do whatever u want with that content in the script snap. Hope that helps.

1 Like


If I use a FileReader to read a file I’ll end up with the config in a document… how do I get both that configuration document AND the document that needs validated into the Script snap so the document can be validated against the configuration?

The config doc and the data doc might have distinct patterns. Based on that, we can process them separately.

Sorry, I’m confused by the answer, I need to apply the transformations defined in the validate document to the data document to see if the data in the data document is valid, so I dont see how I process them seperately…

Can you give me a sample input that contains both data and config docs?