Child Case "New" Button

tindiz
Giga Guru

There is an OOTB "New" button under Child Cases Related Lists in the Case record under "sn_customerservice_case" table.

 

The ask is, if I click on the "New" button, the following fields from the Parent Case must be copied over to the Child Case.

 

Customer Reference - "correlation_id"
Category - "category"
Account - "account"
Contact - "contact"
Short description - "short_description"
Description - "description"
Internal Notes -"work_notes"
Channel - "contact_type"
Priority - "priority"
Assignment group - "assignment_group"
Attachments (if possible)

 

Here is the existing script from the "New" UI action. Please help on how to modify that script so that the fields stated above will be copied over to the Child Case when the "New" button gets clicked on.

 

---

 

function createNewCase() {
    if (g_form.modified) {
        alert(new GwtMessage().getMessage('You have unsaved changes. Please save them to continue.'));
    }
    else if(g_form.getValue('state')=='draft')
    {
            alert(new GwtMessage().getMessage('A case cannot be created on a draft contract.'));
    }else {
        var params = ["sys_id=-1", "sysparm_view=case"];

        if (typeof g_list !== "undefined" && g_list !== null) {
            for (var prop in g_list.submitValues)
                if (g_list.submitValues.hasOwnProperty(prop) && !g_list.doNotSubmitParams[prop])
                    params.push(encodeURIComponent(prop) + '=' + encodeURIComponent(g_list.submitValues[prop]));
        }

        var query = '/sn_customerservice_case.do?' + params.join('&') + '&sysparm_query=';
        var subQuery = '';
        var table = g_form.getTableName();
        var sysID = g_form.getUniqueValue();
        if(table == "customer_account")
            table = "account";
        else if(table == "customer_contact")
            table = "contact";
        else if(table == "service_entitlement")
            table = "entitlement";
        else if(table == "alm_hardware" || table == "alm_asset" ||table == "alm_consumable" || table == "alm_license")
            table = "asset";
        else if(table == "ast_contract")
            table = "contract";
        else if(table == "service_entitlement")
            table = "entitlement";
        else if(table.search("product_model") != -1)
            table = "product";
        else if(table == "change_request") {
            if (g_list.getRelated() === 'sn_customerservice_case.change')
                subQuery += "^" + "change=" + sysID;
            if (g_list.getRelated() === 'sn_customerservice_case.caused_by')
                subQuery += "^" + "caused_by=" + sysID;
        } else if(table == "sn_install_base_sold_product")
            table = "sold_product";
        else if(table == "customer_project")
            table = "project";
        else if(table == "customer_project_task")
            table = "project_task";
        else if (table == "csm_household")
            table = "household";
           
        if(sysID){
            if(query.length > 0)
                subQuery+= "^" + table + "="+ sysID;
            else
                subQuery+=  table + "="+ sysID;
        switch(table){
            case "sn_customerservice_case": subQuery+= getParent();break;
            case "account":  break;
            case "contact": subQuery+= getAccount();break;
            case "entitlement": subQuery+= getAccount() + getProduct() + getAsset()+getContract();break;
            case "contract": subQuery+= getAccount();break;
            case "asset": subQuery+= getAccount() + getModel();break;
            case "default": break;
         }

        }
        if(typeof nowapi !== 'undefined')
            nowapi.g_navigation.open(query+subQuery);
        else
            window.location = (query+subQuery);  
    }
}
   
    function getParent(){
        var subQuery='^parent=';
        if(g_list.getListName()=='sn_customerservice_case.sn_customerservice_case.parent')
            subQuery+=g_form.getUniqueValue();
        return subQuery;
    }
    function getAccount(){
        var subQuery='^account=';
        if(g_form.getValue('account'))
            subQuery+=g_form.getValue('account');
        return subQuery;
    }
    function getProduct(){
        var subQuery='^product=';
        if(g_form.getValue('product'))
            subQuery+=g_form.getValue('product');
        return subQuery;
    }
    function getModel(){
        var subQuery='^product=';
        if(g_form.getValue('model'))
            subQuery+=g_form.getValue('model');
        return subQuery;
    }
    function getContract(){
        var subQuery='^contract=';
        if(g_form.getValue('contract'))
            subQuery+=g_form.getValue('contract');
        return subQuery;
    }
    function getAsset(){    
        var subQuery='^asset=';
        if(g_form.getValue('asset'))
            subQuery+=g_form.getValue('asset');
        return subQuery;
    }
    function getEntitlement(){  
        var subQuery='^entitlement=';
        if(g_form.getValue('entitlement'))
            subQuery+=g_form.getValue('entitlement');
        return subQuery;
    }
5 REPLIES 5

Animesh Das2
Mega Sage

Hi Tindiz,

Can you check from UI action table if the 'New' UI action is on 'global' table? if yes then you can simply create your own UI Action with the same Action Name & your own logic and it will override the global one. Then modify the logic and add some extra condition so that OOB once does not get visible for your case table.

If the 'New' UI action is on specific table itself then you can again create a new UI Action with the same Action Name with your logic and use the 'Overrides' field to override your existing one.

 

If this helps, please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, 

Animesh Das

Hi @Animesh Das2 this New UI action is Customer Service application.

In sn_customerservice_case table.

Hi @Animesh Das2 I will try this solution and will let you know if it works. Thank you.