Regex issue in Virtual agent script, virtual agent ending chat with error.

PriyanshuVerma1
Tera Expert

Hey guys I am trying to create virtual agent flow that checks if user has entered valid incident number in query and then moves forward. The virtual agent script that i wrote on decision node is this, it isn't working at all. Please help me fix the script

 

Our logic was to build it in following way:

if user typed incident number, directly show him incident card.

if user typed generic statement like "show incident" then make him go through complete topic.

(function execute() {
 vaVars.userInput = vaSystem.getSearchText();
  var incidentPattern = /INC000\d{6}/i;
  //var requestedItemPattern = /RITM\d{5}/i;
  
  if(incidentPattern.test(userInput)){
    vaVars.matchIncident = vaVars.userInput.match(incidentPattern);
    return true;
  }
 else{
     return false;}


})()

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

@PriyanshuVerma1 any follow-up help needed? Or was my answer sufficient?

 

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

4 REPLIES 4

-O-
Kilo Patron
Kilo Patron

Where is userInput defined?

Do you maybe mean:

  if(incidentPattern.test(vaVars.userInput)){

?

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Not sure, it might be usufull if you also for example share the error. Though just viewing the script, is this correct?

 

if(incidentPattern.test(userInput)){

 

userInput? All by itself? Perhaps the intend was vaVars.userInput?

 

if(incidentPattern.test(vaVars.userInput)){

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Amit Verma
Kilo Patron
Kilo Patron

Hi @PriyanshuVerma1 

 

I think you are not passing the userInput variable properly. Try passing it like 

if(incidentPattern.test(vaVars.userInput)){

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Mark Roethof
Tera Patron
Tera Patron

@PriyanshuVerma1 any follow-up help needed? Or was my answer sufficient?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn