How to copy submitted Request item in Service Portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2021 03:22 AM
As the attached image below, I would like to copy Request items by clicking on UI Action button.
After clicking on it, all the variable values should be auto-populated into newly created(but not submitted) form of Request item in Service Portal.
After that, the requester will confirm the copied values and modify some of them as necessary, and then submit new Request item.
I believe the article below is a good example to create the UI action, but 'm not sure how to make the script work to copy the variable values in Server script of the widget.
https://serviceportal.io/create-custom-action-buttons-service-portal/
Please kindly give me some advice.
Best Regards,
Aki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2021 06:57 AM
Hi,
then do this; enhance
(function() {
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
try{
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem(gr.cat_item, 1);
// iterate over the variables
var variables = gr.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var name = question.getName();
if(name != '')
cart.setVariable(item, name, gr.variables[name]);
}
var rc = cart.placeOrder();
}
catch(ex){
gs.info(ex);
}
})();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2021 04:30 AM
Thank you for marking my response as helpful.
If my response helped you please mark it correct to close the question so that it benefits future readers as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2021 09:52 AM
when i click on copy button nothing is happening could you please help me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2021 09:01 AM
Hi i was looking for similar requirement could you please explain how did you achieve this with details
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2021 10:03 PM
sample script and steps are shared above.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader