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.

Filter Virtual Agent Topics Using Variables Values

Daniel Sampaio
Tera Expert

Hello,

I have a challenge where I need to gather information about the client's preference—let's say option A, B, or C.
Depending on their choice, a different set of topics should be available: if they choose A, one set of topics; if B, another; and the same for C.

I tried using Live Agent context variables, but when I filter topics by "Who can access this topic" → "Context" and select the variable, it always behaves as if the value is empty.
However, if I remove this condition, I can access the topic and the value is available.

Has anyone encountered this issue before and could give me a hand?

Thanks, everyone! 🙂

1 ACCEPTED SOLUTION

Daniel Sampaio
Tera Expert

Already manage to get a solution.
I've already configured a context variable and a pre-chat survey so I already had the value being set and the interaction record.
On the "who can access this topic" choose script and add something like this:

(function execute() {

gs.warn("Value :"+vaContext.*variable you created*);


var department = 'Customer';

var user_department = '';

try { // GlideRecord will not work for Topic Picker (show me everything)
// I stored the input user department to Context Variable user_department at Pre-chat survey
user_department = vaVars.*variable you created*;
} catch (ex) { // Topic Evaluator cannot access vaVars, so do GlideRecord for the Context Variable
var interaction_id = vaSystem.getInteractionSysId();
var gr = new GlideRecord('interaction');
gr.get(interaction_id);
user_department = gr.context.u_*variable you created*;
}

if (user_department == department) {
return true;
}
else {
return false;
}
 
})()

View solution in original post

1 REPLY 1

Daniel Sampaio
Tera Expert

Already manage to get a solution.
I've already configured a context variable and a pre-chat survey so I already had the value being set and the interaction record.
On the "who can access this topic" choose script and add something like this:

(function execute() {

gs.warn("Value :"+vaContext.*variable you created*);


var department = 'Customer';

var user_department = '';

try { // GlideRecord will not work for Topic Picker (show me everything)
// I stored the input user department to Context Variable user_department at Pre-chat survey
user_department = vaVars.*variable you created*;
} catch (ex) { // Topic Evaluator cannot access vaVars, so do GlideRecord for the Context Variable
var interaction_id = vaSystem.getInteractionSysId();
var gr = new GlideRecord('interaction');
gr.get(interaction_id);
user_department = gr.context.u_*variable you created*;
}

if (user_department == department) {
return true;
}
else {
return false;
}
 
})()