Copy RITM in Catalog Item View

ceraulo
Mega Guru

Hello!

I have a requirement to add a clone/copy an existing RITM record functionality in the Catalog Item View. The requirement is to add a Copy RITM checkbox. When this is selected, a dropdown variable will show all of the RITM records for the item. Selecting a record will populate all of the variables from the old RITM. Has this been done before? 

Please help!

Thank you.

 

1 ACCEPTED SOLUTION

@ceraulo 

Yes, its poosible.

function getRITMdata(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    alert(answer);
    var SkipFieldValue = '|requested_by|on_behalf_of'; //here map your variable names which you dont want to copy
    var jData = JSON.parse(answer);
    for (var key in jData) {
        if (SkipFieldValue.indexOf('|' + key + '|') == -1) {
            g_form.setValue(key, jData[key], jData['dv_' + key]);
        }
    }
}

Thanks
Murthy

Thanks,
Murthy

View solution in original post

16 REPLIES 16

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use onChange catalog client script + GlideAjax and fetch all the variables from that RITM and use JSON structure in the script include so that when you parse you can set the form variables

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Murthy Ch
Giga Sage

@ceraulo 

You can create checkbox and reference variable and use UI policy to make it visible when checkbox is true and use Simple reference qualifier with Item is your catalog item and use GlideAjax and script include to get the ritm variables data. I'm used this code a long back, try if this works.

Onchange client script on RITM variable

function onChange(control, oldValue, newValue, isLoading) {

    var ritm = g_form.getValue('ritm');

    var ajax = new GlideAjax('Newglidingabc');
    ajax.addParam('sysparm_name', 'getRITMDetails');
    ajax.addParam('sysparm_ritm', ritm);
    ajax.getXML(getRITMdata);
}

function getRITMdata(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    //alert(answer);
    var jData = JSON.parse(answer);

    for (var key in jData) {
        g_form.setValue(key, jData[key], jData['dv_' + key]);
    }
}
 getRITMDetails: function() {
        var ritm_number = this.getParameter('sysparm_ritm');
        var set = new GlideappVariablePoolQuestionSet();
        set.setRequestID(ritm_number);
        set.load();
        var vs = set.getFlatQuestions();
        var object = {};
        for (var i = 0; i < vs.size(); i++) {
            if (vs.get(i).getLabel() != '' && vs.get(i).getValue() != '') {
                object[vs.get(i).getName()] = vs.get(i).getValue();
                object['dv_' + vs.get(i).getName()] = vs.get(i).getDisplayValue();
            }
        }
        var data = JSON.stringify(object);
        return data;
    },

Thanks

 

Thanks,
Murthy

@Murthy Chintalapudi 

This works! However, it is copying the values for Requested by and On Behalf of. Is there a way to not include specific variables when copying the values?

Many thanks!

Hi,

the script is just fetching variable values

what is Requested By and On Behalf of? are those also variables?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader