Safer scripting for dates and missing fields

fixes #2239, fixes #2286

These changes prevent script errors because of undefined mappings, prevent script values from being used as source values if the source didn't have a value to begin with, and prevents date scripts from returning 0 when the field is not defined in source.