Article

How to Automatically Create Incident Tickets When Service Fulfillment Includes a Due Date in ServiceNow

Author: Agus Budi Harto, 2025-06-20 01:26:50

In certain scenarios, service catalogs require a completion date that must be followed up by the fulfiller. Examples include catalogs for temporary software installations, notebook loans, USB port openings, and similar tasks. If these tickets are left unattended, fulfillers tend to forget to take necessary follow-up actions, such as uninstalling temporary software, ensuring borrowed notebooks are returned, or re-closing USB ports that should remain disabled.

To address this issue, it is essential to implement a method that prompts fulfillers to take action. One effective approach is to automatically generate incident tickets once the due date specified in the service catalog has passed. This can be achieved by creating a Scheduled Job in ServiceNow that runs under the following conditions:

  1. The current date matches the due date.

  2. The ticket status is already marked as “Closed Complete.”

  3. If a ticket consists of multiple tasks, the Scheduled Job should target the final task, which usually contains a description such as “Execute Request.”

Steps to Set Up a Scheduled Job in ServiceNow

Follow these steps to create the automated process:

  1. Navigate to All > System Definition > Scheduled Jobs.


  2. Click New and select Automatically run a script of your choosing.

  3. Enter a meaningful name in the Name field.

  4. Make sure to check the Active box.

  5. Set Run frequency to Daily.

  6. Specify your Time zone.

  7. Choose the preferred Time for the script to run.

  8. In the Run this script section, input your custom script that checks for tickets meeting the criteria and creates incident tickets accordingly.

    var currentdate = new GlideDate();
    currentdate.getByFormat("yyyy-MM-dd");
    var gr = new GlideRecord("sc_item_option");
    //add the variable id of your catalog below
    gr.addEncodedQuery("item_option_new=150b618c1b85ca107bfd2022f54bcbed^ORitem_option_new=f7b85b4f1b748210f2c2dc61f54bcb56^ORitem_option_new=7176fbca77663300edfc0ff9ba1061e8^ORitem_option_new=cdcf850a1b09c614f2c2dc61f54bcba2");
    gr.addQuery("value",currentdate);
    gr.query();
    while (gr.next()){
        var assGrp = "";
        var id = gr.sys_id.toString();
        var gr2 = new GlideRecord("sc_item_option_mtom");
        gr2.addQuery("sc_item_option",id);
        gr2.query();
        if(gr2.next()){
            var ritm = gr2.request_item.getDisplayValue();
            var ritmid = gr2.request_item.toString();
            var gr3 = new GlideRecord("sc_req_item");
            gr3.addQuery("number",ritm);
            gr3.query();
            if(gr3.next()){
                var req = gr3.request.getDisplayValue();
                var reqid = gr3.request.toString();
                var req_for = gr3.requested_for.toString();
            }
            var state = "";
            var gr6 = new GlideRecord("sc_request");
            gr6.addQuery("sys_id",reqid);
            gr6.query();
            if(gr6.next()){
                state = gr6.state.getDisplayValue();
            }
            var gr5 = new GlideRecord("sc_task");
            gr5.addQuery("request_item",ritmid);
            gr5.query();
            while(gr5.next()){
                var short_desc = gr5.short_description.getDisplayValue();
                if(short_desc=="Execute Request"){
                    assGrp = gr5.assignment_group.toString();
                    if(state=="Closed Complete"){
                        var gr4 = new GlideRecord('incident');
                        gr4.newRecord();
                gr4.short_description = "This incident was created because "+ritm+" of "+req+" had expired.";
                        gr4.impact = '1'; // High impact
                        gr4.urgency = '1'; // High urgency
                        gr4.category = 'Software';
                        gr4.assignment_group = assGrp;//assign to each asignee
                        gr4.caller_id = req_for;
                        gr4.setWorkflow(false);
                        gr4.insert();

                        gr4.work_notes = 'Updated work notes';
                        gr4.setWorkflow(true);
                        gr4.update();

                    }
                }
            }
        }

    }
  9. Save the Scheduled Job.

With this setup, ServiceNow will proactively create incident tickets on due dates to ensure fulfillers don’t overlook critical follow-up tasks, thereby maintaining smooth and efficient service operations.

LinkedIn

Tags: Opinion Servicenow

247 reviews


Add comment