Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Virtual Agent - Create incident- how to set caller to logged in user?

Sandy7
Tera Expert

Hello,

I am setting up virtual agent and trying to do something pretty basic.. when an incident is created from VA, i want to set the Caller field on the incident to the logged in user. 

My code I am using in the create incident part of the flow in VA is: (don't mind the reference to problem, i copied the code: 

The incident is being created, but the caller is not. Can someone help please?


(function execute() {
var problemGr = newGlideRecordSecure('incident');
problemGr.initialize();

problemGr.short_description = vaInputs.short_description2;
problemGr.urgency = vaInputs.urgency1;
problemGR.setValue("caller_id", caller);
 
 
 
vaVars.create_problem = problemGr.insert();
return vaVars.create_problem;
})();

 

11 REPLIES 11

Mark Roethof
Tera Patron
Tera Patron

And when executing your code, there's a very clear message written in the system logs:

com.glide.script.RhinoEcmaError: "problemGR" is not defined.
Task.9582a81e1b4811101ab0fcc6cc4bcb40 : Line(8) column(0)

Looking more closer to your script...

problemGr versus problemGR. A typo!

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

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

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Thanks Mark - I fixed the typo, thanks for noticing that!

However, I have tried these 4 things and am still getting an error: in the screenshot, that's the only error I see when I view the logs. Any ideas? Thanks again for your help

problemGr.caller = vaInputs.user;
// problemGr.caller = gs.getUserID();
//problemGr.setValue("caller_id", caller);
//problemGr.setValue("caller", gs.getUserID());
 
I am trying to look at the logs by testing, then viewing logs, but the only error i get is a very generic one: 
 

find_real_file.png

 

This is the full code I successfully tested with:

(function execute() {

var problemGr = new GlideRecordSecure('incident');
problemGr.initialize();
problemGr.short_description = 'Something';
problemGr.caller_id = vaInputs.user;
 
vaVars.create_problem = problemGr.insert();
return vaVars.create_problem;

})();

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

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

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Mark,

That's perfect.. I really appreciate the help!! Lots of new things to learn!!! Thank you again.

 

Glad it works.

Can you close this topic?

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

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

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn