Related list to show case ticket of parent account and child account in parent account

Joyal Robert
Tera Contributor

Need to create Related list to show case tickets of parent account and child account in parent account form and for child account it should show only child account mapped case ticket.

(function refineQuery(current, parent) {

    // Add your code here, such as current.addQuery(field, value);
    // var casesGr = new GlideRecord('sn_customerservice_case');

    // casesGr.addQuery('account', current.sys_id);
    // // var querys = 'account=' + current.sys_id;
    // caseGr.query();
    // if (current.sys_id == parent.account) {

        var querys = 'account=' + current.sys_id;

        var childAccountGr = new GlideRecord('customer_account');
        childAccountGr.addQuery('account_parent', current.sys_id);
        childAccountGr.query();

        var childAccoundIds = [];
        if (childAccountGr.next()) {
            childAccoundIds.push(childAccountGr.sys_id.toString());
        }
        gs.log("show accounts" + childAccoundIds);

        if (childAccoundIds.length > 0) {
            querys += "^ORaccountIN" + childAccoundIds.join(',');

        } else {
            querys = "account=" + current.sys_id;
        }
   
    gs.log("show query" + querys);
    current.addEncodedQuery(querys);
   
    //current.addEncodedQuery('account='+parent.sys_id);

})(current, parent);
 
This is not working as expected it is showing all the case tickets for all account 
What i required is if parent account has 4 tickets and child account for this particular parent account has 10 tickets and total of 14 tickets need to show parent ticket but for child tickets should show only tickets mapped to that account in case form (in case form we have a field "account" which referred to account table).
the way to find the child accounts is that in account table we have a field "parent account" if any accounts had mentioned parent account, then that account would be child account of that mentioned parent account field.
 
Please help me on this because i am not able to create related list as per this requirement
 
Regards,
Joyal Robert
0 REPLIES 0