cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Script snap / load configuration file

andrew_wait
New Contributor

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.

Background
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.

5 REPLIES 5

smudassir
Employee
Employee

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.

andrew_wait
New Contributor

Thanks

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?

smudassir
Employee
Employee

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

andrew_wait
New Contributor

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โ€ฆ