Modifying the Copy Change UI Action to exclude the specific Change Task Type

mohanambalnanja
Tera Contributor

Hi All,

 

As per the current set up of 'Copy Change' UI action, from the change request related list Change Tasks also getting copied from original change request to new change request.

 

Our requirement is to exclude, If the change task type 'Post Implementation Review' or Change Task type is 'Implementation' and short description contains 'ABC'.

 

Since it is a OOTB script I am not able to find where I can exclude those specific change task types.

 

Script: 

function OnCopyChangeClick()
{
    function addParam(form, name, val)
    {
        var inp = cel('textarea', form);

        inp.name = name;
        inp.value = val;
    }

    var srcSysId = g_form.getUniqueValue();

    var deduplicationKey = "Copy in progress:" + g_form.getUniqueValue() + ":" + g_form.getValue("number");
   
    var updateChange = new GlideAjax("ChangeManagementHelperAsync");

    updateChange.addParam("sysparm_name", "setDeduplicationKey");
    updateChange.addParam("sysparm_changeRequestId", g_form.getUniqueValue());
    updateChange.addParam("sysparm_deduplicationKey", deduplicationKey);

    updateChange.getXML(updateChangeCallback);
   
    function updateChangeCallback(response)
    {
        var result = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
       
        if (result.success)
        {
            var changeUtil = new GlideAjax('ChangeUtils');

            changeUtil.addParam('sysparm_name', 'getChangeQueryParams');
            changeUtil.addParam('sysparm_src_sysid', srcSysId);

            changeUtil.setWantSessionMessages(true);

            changeUtil.getXMLAnswer(function (queryParam)
            {  
                if (queryParam)
                {
                       
                    if (queryParam.includes('change_task.change_request=undefined^')) {
                        queryParam = queryParam.replace('change_task.change_request=undefined^', '');
                    }

                        var gotoURL = new GlideURL('CopyChangeRelatedLists.do');

                        alert('Inside if');

                        gotoURL.setEncode(false);
                        gotoURL.addToken();
                        gotoURL.addParam('srcSysID', srcSysId);
                        gotoURL.addParam('newSysID', '$sys_id');
                        gotoURL.addParam('sysparm_returned_action', '$action');

                        var form = cel('form', document.body);

                        hide(form);

                        form.method = "POST";
                        form.action = g_form.getTableName() + ".do";

                        if (typeof g_ck != 'undefined' && g_ck != "")
                        {
                            addParam(form, 'sysparm_ck', g_ck);
                        }

                        addParam(form, 'sys_id', '-1');
                        addParam(form, 'sysparm_query', queryParam);
                        addParam(form, 'sysparm_goto_url', gotoURL.getURL());

                        form.submit();
                }
            });
        }
    }
}
 
queryParam returns the fields which are copied from original change request.
 
Please help me to find the solution for this scenario.
 
Thanks
4 REPLIES 4

mohanambalnanja
Tera Contributor
Script Include 'ChangeUtilsSNC' function 'copyChangeRelatedLists' coping the task from change request related list
 
copyChangeRelatedLists: function(/*String*/ srcChgSysID, /*String*/ newChgSysID) {
        var ret = true;
        var relatedTables = this._getCsvPropertyValue(this.PROP_CHANGE_RELATED_LISTS, '');
        for (var i = 0; i < relatedTables.length; ++i) {
            var table = relatedTables[i];
            var ans = this._makeRelatedTableCopy(srcChgSysID, newChgSysID, table);
            if (!this._isSet(ans)) {
                this.log.logWarning('copyChangeRelatedLists: Could not copy related table ' + table);
                ret = false;
            }
        }
        return ret;
    },

Ankur Bawiskar
Tera Patron
Tera Patron

@mohanambalnanja 

the main logic is inside the script include "ChangeUtilsSNC" and function "copyChangeRelatedLists"

You cannot update this script include as it's read-only.

I can suggest this

1) exclude change_task from copy logic and copy it using your custom logic using GlideRecord

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

@mohanambalnanja 

Hope you are doing good.

Did my reply answer your question?

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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @mohanambalnanja 

 

If you as per change properties, we can either copy all or no change tasks. Specific is not possible and it will increase technical debt.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************