Copy RITM Widget for Service Portal

Jorge Fernandez
Tera Expert

We have the requirement to create a 'Copy Request Item' widget that uses a previously submitted one. We add a new item into the cart and then copy over almost all the values from the previous RITM, at the end we load the cart page.

 

However we would like to end in a different page. We would like to open the cart item at the end to give it a final look before submitting, but I'm having trouble reaching that point. I don't find a way to access the sys id of the newly created item.

 

Any ideas?

1 ACCEPTED SOLUTION

Paul Deonarine3
Tera Expert

To open the newly created cart item in the cart page after copying over values from a previously submitted RITM, you can use the addVariable method to pass the sys_id of the new cart item to the cart page as a URL parameter. Here's an example script you can use in your widget:

 

function copyRequestItem() {
  // Get the sys_id of the RITM to be copied
  var originalRITM = g_form.getValue('original_ritm_field'); // replace with the actual field name

  // Copy over values to the new cart item
  // ...

  // Save the cart item
  var cart = new sn_sc.CatalogCart();
  cart.save();

  // Get the sys_id of the new cart item
  var newCartItemId = cart.request_item.sys_id;

  // Open the cart page with the new cart item
  var url = '/sc_cart.do?sys_id=-1&sysparm_item=' + newCartItemId;
  g_navigation.open(url);
}

 

In this script, original_ritm_field is the field on the form that contains the sys_id of the RITM to be copied. You'll need to replace this with the actual field name on your form.

The newCartItemId variable gets the sys_id of the newly created cart item from the request_item property of the CatalogCart object. This is then passed to the cart page URL as a URL parameter using the sysparm_item parameter.

Finally, the g_navigation.open method is used to open the cart page with the new cart item.

 

View solution in original post

5 REPLIES 5

@Jorge Fernandez @Paul Deonarine3 So do I need to write below section in client controller section? and the above rest of scripts I can write in Server side right? If you cna give exact details about client controller section script?

-------

// Get the sys_id of the new cart item
  var newCartItemId = cart.request_item.sys_id;
 
  // Open the cart page with the new cart item
  g_navigation.open(url);