- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
03-18-2022 10:31 PM - edited 12-23-2022 09:59 PM
For Service Catalog Items with many fields, it could be helpful to re-order an existing Requested Item by prefilling the new request form with the same values of the RITM to be cloned. This is always useful, for example, if you do not want to enter everything again manually. There are several approaches to this challenge, and my article describes one of them. |
|
Approach
On RITM records we need a button (UI Action) "Clone" which pulls all variable values and put them into a session object for a transfer to the catalog form. Of course, it would also be possible to fetch all the data on client-side with an GlideAjax call, but transferring the data from the server to the client via a session object is more elegant, secure and error-prone.
On the Catalog Item an additional Client Script is required to recognize the variable value transfer and to fill that values into the form. That Client Script is contained in a Variable Set. In this way, the Variable Set can be easily embedded in each Catalog Item, which should support prefilling of the form elements.
Limitations
That approach only works for requests that consist of a single catalog element and therefore do not represent a bundle or an order guide. In addition, the "Clone" button is only available in the UI16 and therefore not in the Service Portal or in a Workspace.
Solution
Script Include
The Script Include CatalogUtils provides a method getVariables() that returns all variables of a given RITM as stringified array of objects. Each of these objects corresponds to a respective Catalog Variable and has the following properties:
strType:
integer value of the variable type or "MVRS" in case the Catalog Item contains Multirow Variable Sets
strName:
variable name
strQuestionText:
label text for a variable
strValue:
the underlying variable value, for example for a reference variable it would be the Sys ID of the target record
strDisplayValue:
the text which is rendered for the variable, for example for a reference variable pointing to the sys_user table it would be the complete name of the referenced user
You can go to https://github.com/mskoddow/sn-scripts/blob/master/CatalogUtils.js for loading the source code of that Script Include.
UI Action
Create a new UI Action with the following parameters:
Name | Clone |
Table | Requested Item (sc_req_item) |
Form Button | (checked) |
Show update | (checked) |
Condition | (define an appropriate condition here to make the UI action available only for authorized users) |
Script |
|
Variable Set
Create a Single-Row Variable Set:
and name it "Basic Initialization" (or choose another name).
This Variable Set will only contain the following Catalog Client Script.
Catalog Client Script
Go to Related List "Catalog Client Scripts" and create a new record:
with the following parameters:
Name | Prefill form with variable values |
Applies to | Variable Set |
UI Type | Desktop |
Type | onLoad |
Variable Set | Common Initialization |
Applies on a Catalog Item view | (checked) |
Script |
|
Screenshot |
Add Variable Set to Catalog Items
The last step is adding the Variable Set to all Catalog Items, which should be able to prefill the form.
For testing purposes, you can pick the OOTB Catalog Item "Sample Item". Order one item and then clone it. In the order form for the clone, all fields should be filled correctly:
A good practice for Catalog Management is to always include such a universal Variable Set into each Catalog Item. That way, you can implement or add common behaviors later without touching hundreds of Catalog Items.
- 5,886 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Couldn't have been more perfect for what I was looking to do, thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Glad that I could help!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
You wouldn't happen to have an idea of how to make this work for a Multi Row Variable Set, would you?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Maik, this is awesome. Edited cause this does exactly as we needed to do. This is amazing!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thankyou, It was incredible. Could you perhaps assist us with the Multi Row Variable Set in the similar way?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
All scripts have been modified to be able of handling multi-row variable sets (MRVS)
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you Maik!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Maik,
I wanted to use this feature for creating a "Refund Item" UI action for billing admins. When customer asks for a refund for a purchased item , the billing admin opens the sc_request_item, clicks "Refund Item" UI action in the related list, It should open a new sc_request_item (not catalog item) within the same request, with all values copied over and admin should be able to edit quantity to negative and save the item. There is an existing UI action to download the altered billing information to be sent to customer
--Your code redirects to catalog item. How can I redirect to the new cloned sc_request_item? I tried below code for redirection in the UI action but it is taking to original item:
gs.setRedirect(
'sc_req_item.do?sys_id='+ current.sys_id + '&sysparm_view=software_center&sysparm_clone=true'
);
--I could not find the documentation for 'sysparm_clone', Can you please give me the documentation link or link within Servicenow. We are in SanDiego 9
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi , How can I use the above method in Service Portal?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Customer not agreeing to create VSet and add to Catalogs, also this will be a manual work for all new catalogs so team has to add this Variable set to all existing and all future new catalogs. Do we have any other mechanism without VSet. Please suggest.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Maik,
Can you think of anyway this could be replicated for Portal usage? We have a scenario where our customers have to enter individual requests but in some cases only a couple of fields need amending between requests. We were hoping to give the client the option so they can recall (clone) a previous request and simply amend the relevant fields to submit a new request, as per my question on forum: https://www.servicenow.com/community/sysadmin-forum/recall-a-previous-request-on-portal-to-complete-...
Regards
Dave
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @Maik Skoddow
Thank you so much for developing this clone UI action. It has proven to be incredibly useful. Could you please provide guidance on how we can modify the redirect to the new clone requested item after clicked on the Clone button, because we do not use an Add to cart function.
Add to Cart function:
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Unfortunately, I don't get your point. Please reach to me on LinkedIn to continue the discussion directly.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @Maik Skoddow
Thank you for creating the clone functionality.
I am facing an issue where list-type variables are not being cloned. Could you please address this?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you for the detailed steps. I have implimented all of them but not able to achive the desired functionality. At the end when testing, I clicked on clone ritm ui action and I get redirected to the previous page/servicenow home. For some reason I am not getting redirected to the catalog item. Any suggestions in what could be the problem and where to check is much appriciated.