How can we call a GliodeAjax in vertual agent script. Is this Possible ?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 06:34 AM
Here I want to validate a start date in virtual agent after user selecting the start date. If the user selected a Sunday then it should populate that "Please select a weekdays from Monday to Friday".
For this I have written a script include .
Script Include:
var WorkingDay_3 = Class.create();
WorkingDay_3.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
WorkDay: function() {
var dateParam = this.getParameter('sysparm_date');
var day = new GlideDateTime(dateParam).getDayOfWeek();
var isWeekend = day == 1 || day == 7; // Sunday or Saturday
return !isWeekend; // Return true if it's a weekday, false if it's a weekend
},
type: 'WorkingDay_3'
});
And Virtual agent Script is :
var day = vaInputs.start_date; // Assuming 'start_date' is the variable name provided by the user in Virtual Agent
var ga = new GlideAjax('WorkingDay_3');
ga.addParam('sysparm_name', 'WorkDay');
ga.addParam('sysparm_date', day);
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer == 'false') {
vaContext.response = 'Please select Week Days from Monday-Friday';
vaContext.closeInteraction = false; // This ensures that the interaction doesn't close
}
});
But it is not working. Can anyone Help me out this.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 07:01 AM
check these links
Virtual Agent User Input format validation [Paris]
Creating your own Virtual Agent Text Input Format Validators
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader