Problem:
Is it possible to perform validation on incoming data?
Solution:
Here’s a simple way to get post-mapping validation working (which means you can re-use the validation script in any mapping script which maps to the same grammar). It could be abstracted with interfaces etc.
- Inside the usersys/mappings’ folder create a new folder; validation.
2. In the validation folder you must place a blank __init__.py file (prefixed and postfixed with double underscores).
3. Create a validation script, e.g.: salesorder.py:
import bots.botsglobal as botsglobal def validate(out): botsglobal.logger.info('Validating sales order') deliveryName = out.get({'BOTSID':'HDR', 'Delname':None}) if not deliveryName: raise Exception('Delivery name not populated')
4. Now in your mapping script import botslib:
import bots.botslib as botslib
5. And at the bottom of your mapping script once you’ve populated out (the output grammar) import the validation script and call the validate method:
try: strategixsovalidation,filename = botslib.botsimport('mappings', 'validation', 'salesorder') except ImportError: raise Exception('Unable to load validation script') else: strategixsovalidation.validate(out)