How to create an incident from record producer through virtual agent?

Community Alums
Not applicable

I want to create an incident with variable section through virtual agent, the same way we create through record producer.

I tried the the way by which we create RITMs but it's not working.

1 ACCEPTED SOLUTION

Several ways possible. Also depending on where the information for those variables would come from.

Though, easiest would be to add a question_answer record scripted. Like below. This would already be similar as having variables when submitted through a record producer.

Personally I would consider doing this more dynamically, fetching the variables from the record producer, etc.. Though below would already work.

var grAnswer = new GlideRecord('question_answer');
grAnswer.initialize();
grAnswer.setValue('table_name', 'incident');
grAnswer.setValue('table_sys_id', 'sys_id_of_your_created_incident, maybe something like vaInputs.create_incident');
grAnswer.setValue('question', 'sys_id_of_the_variable');
grAnswer.setValue('value', 'value_for_the_variable');
grAnswer.setValue('order', '100/200/300/etc');
grAnswer.insert();

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

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

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
Tera Patron
Tera Patron

Hi there,

Can you share what you've tried?

This should be achievable by just creating the Incident (either scripted or using the utility for this), and adding question_answer records.

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

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Community Alums
Not applicable
I am trying with this code, not sure this is correct or not.
But in the same way we are creating RITMs.
we just want all the variables in Incident that we have in record producer.
 
(function execute() {
var itemJSON = new sn_sc.CatItem('3f1dd0320a0a0b99000a53f7604a2ef9').getItemForVA();//sys_id of record producer
vaVars.itemJSON = JSON.stringify(itemJSON);

 

var itemJson = JSON.parse(vaVars.itemJSON);
var cartname = "vacart_" + gs.generateGUID();
var cartObj = new sn_sc.CartJS(cartname);
 
cartObj.setRequestedFor(vaInputs.user);
var variablesObj = {};
variablesObj['requested_for'] = vaVars.request_for;
variablesObj['category'] = vaInputs.category.getValue();
variablesObj['cmdb_ci'] = vaInputs.business_application.getValue();
variablesObj['subcategory'] = vaVars.subsubcategory.getValue();
variablesObj['impact'] = vaInputs.impact.getValue();
variablesObj['comments'] = vaInputs.please_describe_your_issue_below.getValue();
var reqObj = {
"sysparm_id" : itemJson.sys_id,
"variables" : variablesObj
};
cartObj.addToCart(reqObj);
var requestResponse = cartObj.checkoutCart();
vaVars.result_record = "";
var inc = newGlideRecord('incident');
inc.addQuery('sys_id',requestResponse);
inc._query();
 
if(inc._next()) {
vaVars.INCNumber = inc.getDisplayValue();
vaVars.Sys_idINCident = inc.getUniqueValue();
vaVars.result_record = JSON.stringify({
"sys_id" : inc.getUniqueValue(),
"table" : 'incident',
 
});
}
})()

 

This is Cart related, not Incident. So don't see this working.

So how about what I already mentioned? Just creating the Incident (either scripted or using the utility for this), and adding question_answer records. Did you try this already?

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

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Community Alums
Not applicable

I got your point, We are already creating incident via Utility. But how to add variable section(Question answer records)? Can You please elaborate this or if you have sample code, please share.