JSON Scrip Include

var CallerIncidents = Class.create();
CallerIncidents.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getCallersIncs: function() {
        var incArray = [];
        var callersRecords = new GlideRecord('incident');
        callersRecord.addQuery('caller_id', this.getParameter('sysparm_callerID'));
                callersRecords.query();

            while(callersRecords.next()) {
                var incDetails = {};
                incDetails.number = callersRecords.number.toString();
                incDetails.priority = callersRecords.priority.getDisplayValue();
                incDetails.shortDesc = callersRecords.short_description.toString();
            }

                return JSON.stringify(inArray);
    },

    type: 'CallerIncidents'
});

In this example, when the Script Include is called, the script first creates an empty array called incArray.

In then use the passed in parameter sysparm_callerID in a GlideRecord query to gather all of the user's Incident records.

The while loop builds an incDetails object using properties/values from the GlideRecord query and puts that object into the incArray array.

The JSON.stringify() method is used to create a string from a JSON object (incArray) that is returned to the calling Client Script.

results matching ""

    No results matching ""