Parent incident to be created for multiple child incidents on the click of a button.

Aritra Gupta1
Tera Contributor

Hi All,

I have a requirement to create a parent incident on the basis of child incidents selected in the incident table by clicking a button in the banner with many to one relation(i.e. for multiple incidents selected one parent incident to be created). For one to one it is working with this in UI action - 

var gr = new GlideRecord('incident');
gr.initialize();
gr.short_description = 'parent';
var id = gr.insert();
current.parent_incident =id;
current.update();

but I am not able to create for multiple. How can this be achieved??

Thanks in advance!!

1 ACCEPTED SOLUTION

Hello Aritra,

Happy to know that my solution has helped you. I have updated a few more things like a confirmation popup, & an alert if records are selected.

Please go through the below article.

UI ACTION to create a parent incident on the basis of selected records[act as child incidents] from ...

Mark it as helpful & correct, If Applicable

Cheers..!
Happy Learning:)
Tushar

Mark it as helpful or correct, If Applicable


Cheers..!

Happy Learning:)

Tushar

View solution in original post

7 REPLIES 7

Hello Aritra Gupta,

I have tried the same use-case on my personal PDI and it works fine. 

Let's start.....!
We will be creating UI Action & Script include.

UI Action

find_real_file.png

Copy & paste the below script in the section

function OnClick() {
    var id;
	var sysid_array = []; 
	sysid_array = g_list.getChecked();
        var ga = new GlideAjax('InstanceMapper');
        ga.addParam('sysparm_name', 'create');
        ga.addParam('sysparm_ids', sysid_array);
        ga.getXML(answer);
        function answer(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
			alert("The new Incident is created with "+answer);
    }
}

 

Script Include

find_real_file.png

SI - Code

var InstanceMapper = Class.create();
InstanceMapper.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    create: function() {
        var id;
        var ids = this.getParameter('sysparm_ids');
        var id_array = ids.split(',');
        var gr = new GlideRecord('incident');
        gr.initialize();
        gr.short_description = 'parent is almost done';
        id = gr.insert();
        for (var i = 0; i < id_array.length; i++) {
            var inc = new GlideRecord("incident");
            inc.get(id_array[i].toString());
            inc.parent_incident = id;
            inc.update();
        }
        return gr.number;
    },
    type: 'InstanceMapper'
});


OUTPUT:

find_real_file.png

 

Once you will select the tickets from the list & click on the create parent. An alert will popup with the new incident number & under that you will be able to see the children(which one we have selected).

find_real_file.png


Let me know, if you are facing any issues. If my answer helps you please mark it as correct & helpful

Cheers..!
Happy Learning
Tushar

Mark it as helpful or correct, If Applicable


Cheers..!

Happy Learning:)

Tushar

Hi Tushar,

Thank you for your help it is working.

Regards,

Aritra

 

Hello Aritra,

Happy to know that my solution has helped you. I have updated a few more things like a confirmation popup, & an alert if records are selected.

Please go through the below article.

UI ACTION to create a parent incident on the basis of selected records[act as child incidents] from ...

Mark it as helpful & correct, If Applicable

Cheers..!
Happy Learning:)
Tushar

Mark it as helpful or correct, If Applicable


Cheers..!

Happy Learning:)

Tushar