Can we create service request using Virtual Agent bot

Madhura5
Tera Contributor

Hi All,

We have a requirement where the user should be able to order a catalog item using Virtual agent chatbot. 

As of now we have created the topic flow but we are having issues in getting the response (input values) from the user and displaying it in the request.

 

 

1 ACCEPTED SOLUTION

Below a script we use for a Password Reset Catalog Item. We didn't use the API which is available and is var more easy, because our Virtual Agent topic is Scoped... and the API doesn't work scoped 😞 Maybe you could use the API?

So it looks similar to what you have:
- Generate the Request manually
- Generate the Requested Item manually

Though what I'm missing in your script:
- Workflow to be triggered?
In my example: grRITM.setValue('context', grCatItem.workflow);

- Variables + Variable Relationship (which probably is the cause of your Variable Editor being empty)
In my example, look for: sc_item_option and sc_item_option_mtom

Here's an example: 

(function execute() {
    
	var catitemSysId = vaInputs.select_catalog_item;

	var optionsObj = [];

	var grVariableSet = new GlideRecord('io_set_item');
	grVariableSet.addQuery('sc_cat_item', catitemSysId);
	grVariableSet.orderBy('order');
	grVariableSet._query();

	while(grVariableSet._next()) {
		var grVariableSetVariable = new GlideRecord('item_option_new');
		grVariableSetVariable.addQuery('variable_set', grVariableSet.variable_set);
		grVariableSetVariable.addActiveQuery();
		grVariableSetVariable.orderBy('order');
		grVariableSetVariable._query();

		while(grVariableSetVariable._next()) {
			optionsObj.push(
				{
					'sys_id':grVariableSetVariable.getUniqueValue(),
				}
			);
		}
	}

	var grVariable = new GlideRecord('item_option_new');
	grVariable.addQuery('cat_item', catitemSysId);
	grVariable.addActiveQuery();
	grVariable.orderBy('order');
	grVariable._query();

	while(grVariable._next()) {
		optionsObj.push(
			{
				'sys_id':grVariable.getUniqueValue(),
			}
		);
	}

	optionsObj.join();

	// Retrieve Catalog Item
	var grCatItem = new GlideRecord('sc_cat_item');
	grCatItem.get(catitemSysId);

	// Retrieve User 
	var grUser = new GlideRecord('sys_user');
	grUser.get(vaVars.registered_for);

	// Create request
	var grRequest = new GlideRecord('sc_request');
	grRequest.initialize();
	grRequest.setValue('requested_for', vaVars.registered_for);
	grRequest.insert();

	// Create requested item
	var grRITM = new GlideRecord('sc_req_item');
	grRITM.initialize();
	grRITM.setValue('context', grCatItem.workflow);
	grRITM.setValue('request', grRequest.getUniqueValue());		
	grRITM.setValue('cat_item', catitemSysId);
	grRITM.setValue('u_registered_for', vaVars.registered_for);
	grRITM.setValue('opened_by', vaInputs.user);
	grRITM.insert();

	// Create Variable(s) and Variable(s) Ownership
	for(var i = 0; i < optionsObj.length; i++) {
		var grAnswer = new GlideRecord('sc_item_option');
		grAnswer.initialize();
		grAnswer.setValue('item_option_new', optionsObj[i].sys_id);
		if(optionsObj[i].sys_id == '2e03607e37c67600a4d212c543990e11') { // -490 // Registered for
			grAnswer.setValue('value', vaVars.registered_for);
		}
			if(optionsObj[i].sys_id == '7953ec3e37c67600a4d212c543990e7e') { // -480 // Location
				grAnswer.setValue('value', grUser.location);
			}
			if(optionsObj[i].sys_id == 'cc8428fa37c67600a4d212c543990e0a') { // -475 // Registered by
				grAnswer.setValue('value', vaInputs.user);
			}
			if(optionsObj[i].sys_id == '4cd3a0be37c67600a4d212c543990e84') { // -460 // Phone number
				grAnswer.setValue('value', grUser.phone);
			}
			if(optionsObj[i].sys_id == '8504a8fa37c67600a4d212c543990e7a') { // -450 // Cost center
				grAnswer.setValue('value', grUser.cost_center);
			}
			if(optionsObj[i].sys_id == '61b25add376ac300ea011a7943990ee5') { // 150 // Email address
				grAnswer.setValue('value', grUser.email);
			}	
			if(optionsObj[i].sys_id == '16efd347376d9f40ea011a7943990e1a') { // 200 // User ID
				grAnswer.setValue('value', grUser.getValue('user_name'));
			}
			if(optionsObj[i].sys_id == '2ec30b6237ca5380ea011a7943990e0a') { // 225 // Employee number
				grAnswer.setValue('value', grUser.getValue('employee_number'));
			}
			if(optionsObj[i].sys_id == 'b5af5307376d9f40ea011a7943990e7f') { // 350 // System
		 		grAnswer.setValue('value', vaInputs.confirm_system);
			}
			if(optionsObj[i].sys_id == vaInputs.confirm_environment) { // 400 // Production
				grAnswer.setValue('value', true);
			}
			if(optionsObj[i].sys_id == vaInputs.confirm_environment) { // 500 // Acceptance
				grAnswer.setValue('value', true);
			}
			if(optionsObj[i].sys_id == vaInputs.confirm_environment) { // 600 // Quality
				grAnswer.setValue('value', true);
			}
			if(optionsObj[i].sys_id == vaInputs.confirm_environment) { // 700 // Development
				grAnswer.setValue('value', true);
			}

		grAnswer.setValue('order', i + 1);
		grAnswer.insert();

		var grAnswerM2M = new GlideRecord('sc_item_option_mtom');
		grAnswerM2M.newRecord();
		grAnswerM2M.setValue('request_item', grRITM.getUniqueValue());
		grAnswerM2M.setValue('sc_item_option', grAnswer.getUniqueValue());
		grAnswerM2M.insert();
	}

	// Start workflow assigned to Catalog Item
	new global.Workflow().startFlow(grCatItem.workflow, grRITM, '', '');

	vaVars.record = grRITM.getUniqueValue();
    vaVars.number = grRITM.number;
    
})()

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

9 REPLIES 9

@Mark Roethof , this has been a GREAT HELP and encouragement for me in starting my work in VA, thanks to your detailed script along with COMMENTS and EXPLANATION for guidance. Thanks once again. 

Vishal Khandve
Kilo Sage

Hi Madhura, 

Yes we can.

 

just go to Collaboration > Virtual Agent > designer

and activate the  order item topic

find_real_file.png

Thanks,

Vishal

Hi there,

The Order an Item topic, doesn't create Requests for you. It just gives you an URL to a Catalog Item.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

sarabjeet
Giga Expert

Hi @Mark Roethof 

We have user criteria associated with catalog item and it is not working when we are raising that request from VA. 
Also, when ESS users are trying to raise it for someone else and trying to add an attachment, it is throwing an error and redirecting to live agent.
Could you please let me know how to handle this?
 
Regards,
Sarabjeet 

Hi Mark,

Could you please help with this.

 

Regards,

Sarabjeet