Need help in Virtual Agent scripting

Admin7267
Kilo Sage

I have requirement to set the category of the incident based on the short description provided by the user.

Eg: If user enters "My laptop is not getting charged" and sys_choice table has laptop then need to set the Laptop as the category of the incident. I have written the below code for testing purpose and it's not working.

Admin7267_0-1715100167499.png

 

var str = vaInputs.sub;
var words = str.split(" ");

for (var i = 0; i < words.length-1; i++) { 
    var gr1 = new GlideRecord('sys_choice');
    gr1.addEncodedQuery('name=incident^element=category^inactive=false');
    gr1.addQuery('label',words[i]);
    gr1.query();
    while(gr1.next()){
       vaVars.subcat1=gr1.label;             // subcat1 is defined in scripted variables in the topic
       gs.log("CATEGORY IS  "+vaVars.subcat1 );
       gs. log('Category is selected as '+vaVars.subcat1);
    }

}

 

 

3 REPLIES 3

Muralidharan BS
Mega Sage
Mega Sage

HI @Admin7267 , 

 

You can use glidechoicelist to achieve this, checkout this article explaining solution for similar problem, Consider the category input should also be choice else you will leave room for typo errors. 

 

https://www.servicenow.com/community/virtual-agent-nlu-forum/display-choice-field-values-depend-on-o...

 

Thanks

Thanks for the response @Muralidharan BS , but my requirement is different. 

Need to get category from the short description provided

Eg: If user enters "My laptop is not getting charged" and sys_choice table has laptop then need to set the Laptop as the category of the incident.

Chris D
Mega Sage
Mega Sage

You may not actually need to manually script this. This sounds like a great use case for using NLU entities and I'd recommend you exploring NLU to learn more.

As a quick summary, "Laptop" would be set as an entity (i.e. "#Device" or "#Incident_Category"). Then in VA Designer you create a user input and use "slot-filling" in the user input to map the entity to the input, then when the topic creates/updates the RITM, you map the INC Category to the VA Input - and all this is done with no code.