- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 01:04 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 08:47 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 08:47 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 10:54 AM
Hi Paul
is the above script to be written in Server side in Widget and that's all required or if you can give details from first point like how to copy to cart and then read from cart , edit variable values and submit new RITM.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 07:33 AM - edited 07-12-2023 09:53 AM
Hi @Paul Deonarine3 @Jorge Fernandez
May I get the details from beginning. I tried to write in Server side script to get values from RITM variables etc and then save in cart and Open there itself so that user should edit values as per need and submit. But its not working. Script which I had written as beow:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 08:28 AM
You get the cartItemID at the Server script and then you pass the value to the Client Controller script to open the cart page