12-01-2021 04:39 AM
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.
12-01-2021 05:12 AM
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.
12-01-2021 05:53 AM
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?
12-01-2021 08:00 AM
The config doc and the data doc might have distinct patterns. Based on that, we can process them separately.
12-02-2021 12:20 AM
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…