{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":32930,"path":"it-service-management/incident-management/t_CreatingAUIAction.md","title":"Create a UI action to close multiple incidents","bundle":null,"doc_type":null,"release":"australia","body":"\n# Create a UI action to close multiple incidents\n\nCreate a UI action to close multiple incidents at once from the **Actions** list in the list view.\n\n## Before you begin\n\nRole required: business\\_rule\\_admin \\(for business rule\\), ui\\_action\\_admin \\(for UI action\\), or admin\n\n## About this task\n\nClosing an incident from **Actions** list adds the same close note to all the incidents that are closed and does not require the list\\_updater role. Implementing this process requires a script include that is referred from a UI action and a custom UI page.\n\n## Procedure\n\n1.  Navigate to **All** &gt; **System Definition** &gt; **Script Includes** and click **New**.\n\n2.  Create the script includes with the following information.\n\n    -   **Name**: IncidentClosure\n    -   **Client callable**: Select the check box\n    -   **Active**: Select the check box\n    -   **Script**: Paste the following information:\n\n        ```\n        var IncidentClosure = Class.create();\n        IncidentClosure.prototype = Object.extendsObject(AbstractAjaxProcessor, {\n            closeIncidents: function() {\n                var selectedIncidents = this.getParameter(\"sysparm_incidents\");\n                var notes = this.getParameter(\"sysparm_closeNote\");\n                var code = this.getParameter(\"sysparm_closeCode\");\n                var incidentGr = new GlideRecord('incident');\n                incidentGr.addQuery('sys_id', 'IN', selectedIncidents);\n                incidentGr.query();\n                while (incidentGr.next()) {\n                    incidentGr.setValue('state', 7);\n                    incidentGr.setValue('close_notes', notes);\n                    incidentGr.setValue('close_code', code);    \n                    incidentGr.update();\n                }\n                return true;\n            },\n            \n           type: 'IncidentClosure'\n        });\n        ```\n\n3.  Save the record.\n\n4.  Create the following steps to create a UI page.\n\n    -   **Name**: mandatory\\_fields\\_to\\_close\\_incident\\_ui\n    -   **HTML**: Paste the following information:\n\n        ```\n        <?xml version=\"1.0\" encoding=\"utf-8\" ?>\n        <j:jelly trim=\"false\" xmlns:j=\"jelly:core\" xmlns:g=\"glide\" xmlns:j2=\"null\" xmlns:g2=\"null\">\n            <style>\n                #content_row .reference-label {\n                    padding-right: 15px;\n                }\n        \n                #page_timing_div {\n                    display: none;\n                }\n            </style>\n            <form class=\"form-horizontal\">\n                <div class=\"form-group\">\n                    <label class=\"col-xs-4 control-label\">\n                        <span style=\"padding-right: 5px;\"></span>\n                        <span class=\"label-text\">${gs.getMessage('Resolution code')}</span>\n                    </label>\n                    <div class=\"col-xs-5 form-field input_controls\" style=\"line-height: 32px;\">\n                        <select name=\"closeCode\" id=\"closeCode\">\n                            <option value=\"\" selected=\"SELECTED\" role=\"option\">-- None --</option>\n                            <option value=\"Solved (Work Around)\" role=\"option\">Solved (Work Around)</option>\n                            <option value=\"Solved (Permanently)\" role=\"option\">Solved (Permanently)</option>\n                            <option value=\"Solved Remotely (Work Around)\" role=\"option\">Solved Remotely (Work Around)</option>\n                            <option value=\"Solved Remotely (Permanently)\" role=\"option\">Solved Remotely (Permanently)</option>\n                            <option value=\"Not Solved (Not Reproducible)\" role=\"option\">Not Solved (Not Reproducible)</option>\n                            <option value=\"Not Solved (Too Costly)\" role=\"option\">Not Solved (Too Costly)</option>\n                            <option value=\"Closed/Resolved by Caller\" role=\"option\">Closed/Resolved by Caller</option>\n                        </select>\n                    </div>\n                </div>\n                <div class=\"form-group\">\n                    <label class=\"col-xs-4 control-label\">\n                        <span class=\"label-text\" style=\"\">${gs.getMessage('Resolution Notes')}</span>\n                    </label>\n                    <div class=\"col-xs-7 form-field input_controls\">\n                        <textarea required=\"true\" class=\"form-control\" value=\"closeNotes\" id=\"closeNotes\" type=\"text\"></textarea>\n                    </div>\n                </div>\n                <div class=\"form-group\" style=\"padding-right:20px;margin-bottom:0;padding-left: 75%; line-height: 45px;\">\n                    <g:dialog_button id=\"cancel_button\" type=\"button\" style_class=\"$btn btn-default\" onclick=\"actionCancel()\" style=\"min-width: 5em;\">${gs.getMessage('Cancel')}</g:dialog_button>\n        \n                    <g:dialog_button id=\"ok_button\" type=\"button\" onclick=\"actionOK()\" style_class=\"btn btn-primary\" style=\"min-width: 5em;\">${gs.getMessage('OK')}</g:dialog_button>\n                    <div class=\"clearfix\"></div>\n                </div>\n            </form>\n        </j:jelly>\n        ```\n\n    -   **Client script**: Paste the following information:\n\n        ```\n        function actionOK() {\n            var modal = GlideModal.prototype.get(\"mandatory_fields_to_close_incident_ui\");\n            var incidents = modal.getPreference(\"selected_incidents\");\n            if (incidents) {\n                //close the incidents\n                var glideAjax = new GlideAjax(\"IncidentClosure\");\n                glideAjax.addParam(\"sysparm_name\", \"closeIncidents\");\n                glideAjax.addParam(\"sysparm_incidents\", incidents);\n                glideAjax.addParam(\"sysparm_closeCode\", $(\"closeCode\").value);\n                glideAjax.addParam(\"sysparm_closeNote\", $(\"closeNotes\").value);\n                glideAjax.getXMLAnswer(function(answer) {\n                    GlideModal.prototype.get(\"mandatory_fields_to_close_incident_ui\").destroy();\n                    GlideList2.get('incident').refresh();\n                });\n            }\n        }\n        \n        function actionCancel() {\n            GlideModal.prototype.get(\"mandatory_fields_to_close_incident_ui\").destroy();\n        }\n        \n        (function() {\n            var okButton = gel('ok_button');\n            var closeCodeEl = gel('closeCode');\n            var closeNotesEl = gel('closeNotes');\n            okButton.disabled = true;\n            closeNotesEl.value = \"\";\n            closeCodeEl.on('change', function() {\n                if (closeCodeEl.value !==\"\" && closeNotesEl.value !==\"\")\n                    okButton.disabled = false;\n                else\n                    okButton.disabled = true;\n            });\n            closeNotesEl.on('input', function() {\n                if (closeCodeEl.value !==\"\" && closeNotesEl.value !==\"\")\n                    okButton.disabled = false;\n                else\n                    okButton.disabled = true;\n            });\n        })();\n        ```\n\n5.  Save the record.\n\n6.  Complete the following steps to create the UI action for closing multiple incidents.\n\n    1.  Navigate to **System Definition** &gt; **UI Actions** and click **New**.\n\n    2.  Create the UI actions with the following information:\n\n        -   **Name**: Close incidents\n        -   **Table**: Incident \\[incident\\]\n        -   **Show update**: Select the check box\n        -   **List choice**: Select the check box\n        -   **List v2 Compatible**: Select the check box\n        -   **Client**: Select the check box\n        -   **Onclick**: closeIncidents\\(\\)\n        -   **Condition**: current.getValue\\('state'\\) !== '7'\n        -   **Script**: paste the following information\n        ```\n        function closeIncidents() {\n            var list = GlideList2.get('incident');\n            var title = list.getTitle();\n            var incidents = list.getChecked();\n            if (incidents) {\n                var o = new GlideModal('mandatory_fields_to_close_incident_ui');\n                    getMessage(\"Close Incidents\", function(msg) {\n                        o.setTitle(msg);\n                        o.setPreference('selected_incidents', incidents);\n                        o.render();\n                    });\n                }\n            }\n                   \n        ```\n\n7.  Save the record.\n\n\n## Result\n\nService desk agents can close multiple incidents using **Close incidents** in the **Actions** list below the Incident list.\n\n**Parent Topic:**[Incident resolution and closure](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/it-service-management/incident-management/c_IncidentResolutionAndRecovery.md)\n\n"}}