Copy Change Request

ANGAD SHARMA
Tera Contributor

Hello Everyone, I have these requirements and i am stuck on this. Can anyone help me to get out this.
-----------------------------------------------------

"

When I click on "Copy Change" from the context menu,

The system should prompt whether I want to copy the CTASKS associated with the Change Request

"This Change has associated CTASK(s), would you like to copy those CTASK(s)?"

If I choose yes, then, all related Change Task should be copied along with the new Change Request.

If I choose no, then no related change Task should be copied along with the new Change Request.(i.e. after choose no, change request should be copied but no related change task.)"

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @ANGAD SHARMA 

 

This has been derived from Change properties:

 

AGLearnNGrow_0-1709833543976.png

 

 

Create a Alert message and call this property.

*************************************************************************************************************
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]

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

Hi @Dr Atul G- LNG /Atul,

Thanks for your response!

Based on my requirements i have modified Ui Action(Copy Change) script. 👇

 

function OnCopyChangeClick() {
    // Prompt the user for confirmation
    var copyCTASKs = confirm("This Change has associated CTASK(s). Would you like to copy those CTASK(s)?");

    if (copyCTASKs) {
        // User wants to copy CTASKs, proceed with the copy process
        copyChange(true);
    } else {
        // User does not want to copy CTASKs, proceed with the copy process without CTASKs
        copyChange(false);
    }
}

function copyChange(includeCTASKs) {
    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) {
            var gotoURL = new GlideURL('CopyChangeRelatedLists.do');
            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());

            // Add parameter to include or exclude CTASKs based on user choice
            addParam(form, 'includeCTASKs', includeCTASKs ? 'true' : 'false');

            form.submit();
        }
    });
}
 

When I click on "Copy Change" from the context menu, popup message got populated -👇

"This Change has associated CTASK(s), would you like to copy those CTASK(s)?"

If I choose yes, then, all related Change Task is copying along with the new Change Request.

but, when i choose cancel, then related change task also copying with new change request.

 

this is happening because of this-👇

in Ui Action a script include calling - "ChangeUtils"( it is OOO) and another scripts include "ChangeUtilsSNCcalling in "ChangeUtils".  
A system properties 'com.snc.change_request.copy.related_lists' calling by "ChangeUtilsSNC" which is readable only.
 
as i explain you all the scenario, can you help me?

Hi @ANGAD SHARMA 

 

in Ui Action a script include calling - "ChangeUtils"( it is OOO) and another scripts include "ChangeUtilsSNCcalling in "ChangeUtils".  
A system properties 'com.snc.change_request.copy.related_lists' calling by "ChangeUtilsSNC" which is readable only
 
yes, you are correct. So in this case what i can suggest, create 2 UI action one is with task and 1 is without task. Else changing or understanding OOTB scripts will consume more time.
*************************************************************************************************************
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]

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