Create Unplanned Outage from Issuer Case via UI Action

chetanasand
Tera Contributor

Please suggest me development steps and help me with correct script for below story. I want configuration item script to be done in script include and call it in UI action.

chetanasand_0-1776369334998.pngchetanasand_1-1776369375353.png

chetanasand_2-1776369421010.png

 

1 REPLY 1

Tanushree Maiti
Kilo Patron

Hi @chetanasand 

 

Just ensure to first try solving the problem on your own. If you get stuck, then reach out to community members for the guidance .

This approach not only helps you find solutions but also ensures you continue learning and developing your skills . 

 

Sharing you Draft sample script ( not tested) . At least you can start with it and correct script as per your requirement. Take help of logging if you stuck somewhere /not getting expected output.

 

1) UI Action:

  • Name: Create Outage
  • Table: Case [sn_customerservice_case]
  • Active: Checked
  • Show Insert/Update: Checked
  • Client: Checked
  • Onclick: runClient()
  • Script:
function runClient() {
    var ga = new GlideAjax('CreateCaseOutageUtils');
    ga.addParam('sysparm_name', 'createOutageFromCase');
    ga.addParam('sysparm_case_id', g_form.getUniqueValue());
    ga.getXMLAnswer(function(answer) {
        if (answer.startsWith('Success')) {
            g_form.addInfoMessage(answer);
            g_form.save();         } else {
            g_form.addErrorMessage(answer);
        }
    });
}

 

2) Script Include

  • Name: CreateCaseOutageUtils 
  • Client callable: Checked
  • Script:
var CreateCaseOutageUtils = Class.create();
CreateCaseOutageUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    createOutageFromCase: function() {
        var caseSysId = this.getParameter('sysparm_case_id');
        if (!caseSysId) return "Error: No Case ID";

        var grCase = new GlideRecord('sn_customerservice_case'); // Update table name ,if needed
        if (grCase.get(caseSysId)) {
            
           var accountId = grCase.account;
            if (!accountId) return "Error: No Account associated";
            
            var grAccount = new GlideRecord('customer_account');
            grAccount.get(accountId);
            var platform = grAccount.u_platform; 
var serviceOfferingName = grCase.sold_product.getDisplayValue(); // Assuming Sold Product is reference var grOffering = new GlideRecord('service_offering'); grOffering.addQuery('name', serviceOfferingName); grOffering.addQuery('u_platform', platform); // Assuming service offering has same platform field grOffering.query(); if (grOffering.next()) { var grOutage = new GlideRecord('cmdb_ci_outage'); grOutage.initialize(); grOutage.cmdb_ci = grOffering.sys_id; grOutage.type = 'outage'; grOutage.begin = grCase.opened_at; grOutage.description = "Outage created from " + grCase.number; var outageSysId = grOutage.insert(); grCase.work_notes = "Outage created: [code]<a href='/cmdb_ci_outage.do?sys_id=" + outageSysId + "'>" + grOutage.number + "</a>[/code]"; grCase.update(); return "Success: " + grOutage.number; } else { return "Error: No matching Service Offering found."; } } return "Error: Case not found"; }, type: 'CreateCaseOutageUtils'});
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: