ServiceNow

  • Ensuring Data Integrity in Custom Scoped Applications with Contractual

    Written on

    under

    Building custom scoped applications in ServiceNow, it is important to make sure data is clean, consistent, and fits the expected format. IMO – ServiceNow doesn’t do enough to enforce data validation. To amend that, I wrote Contractual.

    What is Contractual?

    Contractual is a handy script include for consistent data validation. You can wrap variables or objects and run all kinds of checks on them. If something’s off, it throws a clear error. Its fluent interface makes validation code neat and readable.

    (more…)
  • Better error handling with exception objects

    Written on

    under

    If you’ve spent time writing ServiceNow Script Includes, you’ve probably run into the classic issue of checking for errors when working with GlideRecord. Normally, you’d write code like this:

    var gr = new GlideRecord('incident');
    gr.short_description = 'Test Incident';
    if (!gr.insert()) {
        gs.error('Failed to insert: ' + gr.getLastErrorMessage());
    }

    While this works, it’s easy to miss error handling, especially in larger scripts, and the logic for checking success/failure can get repetitive.

    (more…)