How to copy submitted Request item in Service Portal?

Aki17
Kilo Guru

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.

find_real_file.png

 

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

16 REPLIES 16

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Aki 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

when i click on copy button nothing is happening could you please help me

Hi i was looking for similar requirement could you please explain how did you achieve this with details

sample script and steps are shared above.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader