Add values coming from different tickets to a list collector without removing old ones

Kumar147
Tera Contributor

Hello, 

I am having a list collector field on a parent ticket which will get change requests associated with different child tickets related to the parent ticket. sometime same change number is associated with different child tickets and so i want to restrict the adding of same change number multiple times. however i can restrict the duplicate ones, but its also removing the existing tickets added to parent ticket and adding the values coming from child tickets. How can i add the change values coming from different child tickets without adding duplicate and without removing old tickets.

I am using script as follows: 

    var arr = [];
    var gr = new GlideRecord('child_table');
    gr.addQuery('parent.sys_id', current.parent);
    gr.query();
    while (gr.next()) {
        var gr1 = new GlideRecord('Parent_table');
        gr1.addQuery('sys_id', gr.parent);
        gr1.query();
        while (gr1.next()) {
            arr.push(gr.getValue('u_related_change'));
            var result = arr.join(',');
            var arrnew = result.split(',');
            var arrayUtil = new ArrayUtil();
            var arr1 = arrayUtil.unique(arrnew);
            gr1.u_dependent_change = arr1.join(',');
            gr1.update();
        }
    }

 

Thanks in advance.

9 REPLIES 9

@Kumar147 

So 1 parent can have multiple childs.

so that list field is storing child CHGs?

where are you writing this script and what debugging did you perform?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello @Ankur Bawiskar 

Yes, One parent can have multiple childs and its storing changes and also one child can store multiple changes. When i tried its getting added two times, means its getting duplicated.

@Kumar147 

then it seems the child has duplicate changes populated in that field and hence it's causing the issue

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello @Ankur Bawiskar 

Child may have multiple changes and a change can link to multiple childs under same parent. From child tickets I am getting valid response after removing duplicates. Only when we are passing them to parent, they are duplicated

@Kumar147 

so what debugging did you do?

Any child has duplicate change inside it?

share the logs before and after making the unique array check

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader