logo

NJP

Copy Change - modify the description

Import · Feb 05, 2020 · article

Copy change - UI action in change management.

As we got a requirement to add text in the description of copied change with the originated change number in it

example if a change has a description like: modify an existing workflow

the expected result of copied change description should like: Change copied from CHG******, modify an existing workflow

here is the code

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

    var srcSysId = g_form.getUniqueValue();

    var ga = new GlideAjax('ChangeUtils');
    ga.addParam('sysparm_name', 'getChangeQueryParams');
    ga.addParam('sysparm_src_sysid', srcSysId);
    ga.setWantSessionMessages(true);
    ga.getXMLAnswer(function (queryParam) {
        if (queryParam) {
            //alert(queryParam);

            var nDesc = queryParam +"^description = Change copied from "+g_form.getValue("number")+"\n"+g_form.getValue("description");
            queryParam=nDesc;
            var gotoUrl = [];
            gotoUrl.push('srcSysID=' + srcSysId);
            gotoUrl.push('newSysID=$sys_id');
            gotoUrl.push('sysparm_returned_action=$action');

            gotoUrl = 'CopyChangeRelatedLists.do?' + gotoUrl.join('&');

            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);
            form.submit();
        }
    });
}

as this functionality is OOB please be sure to create a new UI action and apply the above code it then call new UI Action in Overrides| sys_overrides UI Action of OOB one (or) deactivate the OOB one and create new UI Action and use abov...

sys_overrides

imageimage

View original source

https://www.servicenow.com/community/developer-articles/copy-change-modify-the-description/ta-p/2323625