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

Hi @ColinAngstadt1 

In the above code which you shared

where did you written the function getdata() ?

 

Thanks,
Murthy

Hi Murthy!

 

I didn't realize that was needed (novice coder)

 

Could you guide me in creating it?  or send me in the right direction?

 

Any help is appreciated.

 

Thanks!

Hi Murthy!

 

Thanks for taking a look.  I am a novice coder and didn't realize what i was missing.

 

Could you help me out in with writing the getdata function?  or send me in the correct direciton?

 

Thanks!

Hi @ColinAngstadt1 

No issues. I can help you out here.

Create a on change client script on RITM variable like below:

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

    var ritm = g_form.getValue('ritm');  //here replace with your RITM variable name

    var ajax = new GlideAjax('Newglidingabc');  //script include name
    ajax.addParam('sysparm_name', 'getRITMDetails');  //function name
    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]);
    }
}

Now create a script include with client callable and use the below function:

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;
    },

Let me know if you stuck anywhere. Happy to help:)

Thanks,
Murthy

Hi Murthy!

 

I really appreciate your help and i feel like its almost there, but still not working.

 

Let me share with you what I have:

 

RITM variable name that is pulling in the RITM to copy = ritm

scripts includes name =copyddu

 

my on change script, with "ritm: selected as the variable, and the box checked for Catalog item view


function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

  var ritm = g_form.getValue('ritm');  //here replace with your RITM variable name

    var ajax = new GlideAjax('copyddu');  //script include name
    ajax.addParam('sysparm_name', 'getRITMDetails');  //function name
    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]);
    }
}
script inlcudes names copyddu

function getRITMDetails() {
    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;
}

 

I have been playing with this all morning and have not made any progress (other then getting rid of a javascript error on the browser from another faulty script)

 

Any ideas here?

 

Thanks!!

 

Colin