
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2020 07:32 AM
Hey SN Comm,
I am looking for some help implementing a conversation through VA Chatbot, to be able to resolve HR Cases.
I have taking the 'Resolve Incident' flow and copied it, change the table and state to match the hr case table (so I thought).
But the chatbot keeps returning 'No Records Found' decision.
Here is the Resolve Incident 'Get Incidents' Script Action:
(function execute() {
var gr = new GlideRecordSecure('incident');
gr.addQuery('assigned_to', vaInputs.user);
gr.addQuery('state', '!=', vaVars.resolved_state)
gr.addActiveQuery();
gr.orderByDesc('sys_updated_on');
var start = parseInt(vaVars.index);
var end = start + parseInt(vaVars.limit);
gr.chooseWindow(start, end, true);
gr.query();
vaVars.count = gr.getRowCount();
var results = [];
while(gr.next()) {
results.push({
'value': gr.getUniqueValue(),
'label': gs.getMessage('{0} [{1}]', [gr.getDisplayValue('short_description'),gr.getDisplayValue('number')])
});
}
vaVars.results = JSON.stringify(results);
})()
And here are the next steps it takes once it gets records
Here is what I changed to try and match HR Case tables:
(function execute() {
var gr = new GlideRecord('sn_hr_core_case');
gr.addQuery('assigned_to', vaInputs.user);
gr.addQuery('state', '!=', vaVars.closed_complete_state)
gr.addActiveQuery();
gr.orderByDesc('sys_updated_on');
var start = parseInt(vaVars.index);
var end = start + parseInt(vaVars.limit);
gr.chooseWindow(start, end, true);
gr.query();
vaVars.count = gr.getRowCount();
var results = [];
while(gr.next()) {
results.push({
'value': gr.getUniqueValue(),
'label': gs.getMessage('{0} [{1}]', [gr.getDisplayValue('short_description'),gr.getDisplayValue('number')])
});
}
vaVars.results = JSON.stringify(results);
})()
And here are my next steps to match:
I keep getting taken to the No Cases Found decision and I am thinking I have the table set up wrong from the very first step. I definitely have cases assigned to myself.
Anyone able to assist with this?
Thank you!
-Rob
Solved! Go to Solution.
- Labels:
-
Virtual Agent

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2020 12:56 PM
Okay - looked at the code with a co-worker and we were able to figure it out!
realized that vaVars.awaiting_acceptance_state means nothing for scoped hr.
It wants the value instead of the label name - i.e. awaiting acceptance is '20'.
I also had my u_case_resolution get function in the wrong place, for how we handle on the native side.
here is the code the works perfectly:
(function execute() {
var success = null;
var gr = new GlideRecordSecure('sn_hr_core_case');
if (gr.get(vaVars.sys_id)) {
//set state to Awaiting Acceptance
gs.info("changing state");
gs.info("current state is: " + gr.state);
gr.u_case_resolution = vaInputs.u_case_resolution.getValue();
gr.state = 20;
gs.info("state has changed to:" + gr.state);
var operation = vaInputs.update_comments.getValue();
if (operation != 'cancel') {
if ((operation == 'comment' || operation == 'both') && vaInputs.comment.getValue().trim() != ''){
gr.comments = vaInputs.comment;
}
if ((operation == 'work_notes' || operation == 'both') && vaInputs.work_notes.getValue().trim() != ''){
gr.work_notes = vaInputs.work_notes;
}
}
success = gr.update();
}
vaVars.success = '' + (success != null);
})()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2020 11:39 AM
Yes - I realized that earlier but never said so here. hahaha
I changed it to move to awaiting acceptance state - It's "working". While viewing the case form at the same time, the LIVE symbol shows up as if the State Field is being changed automatically - but never moves out of WIP State.
Trying to think of what would be hitting the field and then stop it from moving forward.
So for us on the native side, we click UI Action 'Close Complete', which brings up a dialog box to enter in resolution notes - once clicking OK, those notes are captured into a custom field, case moves to awaiting acceptance, email is triggered to be sent to the Requestor to accept/reject the resolution.
Is there maybe too many things happening on the native side to make this VA Design work properly?
Thanks,
-Rob

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2020 06:55 AM
Hey
Any thought(s) based off my last comment?
Along with that, here is the code I have from the workflow using a Script Action to update the case with my entered note and trying to move the state from WIP to Awaiting Acceptance.
Again, the field is being touched as I can see the live icon displayed when this script is being passed. However, the state stays on WIP and never moved. I tried other states just to see if it would move, but it does not.
Thanks!
-Rob
(function execute() {
var success = null;
var gr = new GlideRecordSecure('sn_hr_core_case');
if (gr.get(vaVars.sys_id)) {
//set state to Awaiting Acceptance
gr.state = vaVars.awaiting_acceptance_state;
//gr.close_code = vaInputs.resolution.getValue();
gr.u_special_note = vaInputs.u_case_resolution;
var operation = vaInputs.update_comments.getValue();
if (operation != 'cancel') {
if ((operation == 'comment' || operation == 'both') && vaInputs.comment.getValue().trim() != ''){
gr.comments = vaInputs.comment;
}
if ((operation == 'work_notes' || operation == 'both') && vaInputs.work_notes.getValue().trim() != ''){
gr.work_notes = vaInputs.work_notes;
}
}
success = gr.update();
}
vaVars.success = '' + (success != null);
})()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2020 10:25 AM
Hi Rob,
About "So for us on the native side, we click UI Action 'Close Complete', which brings up a dialog box to enter in resolution notes - once clicking OK, those notes are captured into a custom field, case moves to awaiting acceptance, email is triggered to be sent to the Requestor to accept/reject the resolution."
Don't know if this could be an issue. Though you do mention in your recent comment that the state stays WIP.
Could you add debugging to the script? gs.info etc.. For example, is below valid? Can you debug "vaVars.awaiting_acceptance_state"? Does this give you the expected value?
gr.state = vaVars.awaiting_acceptance_state;
Also add debugging to see how far the script goes, if "operation" has the expected value, if "operation" is reached, does vaVars.sys_id contain the expected value, etc..
With the out-of-the-box topic, slightly modified to sn_hr_core_case, if I perform twice an update on state, I can simply close the case. First update on state causes the case to be set on "Awaiting acceptance", second update on state causes the case to be closed.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2020 10:55 AM
Okay - so here is what I added for some debugging:
(function execute() {
var success = null;
var gr = new GlideRecordSecure('sn_hr_core_case');
if (gr.get(vaVars.sys_id)) {
//set state to Awaiting Acceptance
gs.info("changing state");
gr.state = vaVars.awaiting_acceptance_state;
gs.info("state has changed to:" + gr.state);
//gr.close_code = vaInputs.resolution.getValue();
gr.u_special_note = vaInputs.u_case_resolution;
var operation = vaInputs.update_comments.getValue();
if (operation != 'cancel') {
if ((operation == 'comment' || operation == 'both') && vaInputs.comment.getValue().trim() != ''){
gr.comments = vaInputs.comment;
}
if ((operation == 'work_notes' || operation == 'both') && vaInputs.work_notes.getValue().trim() != ''){
gr.work_notes = vaInputs.work_notes;
}
}
success = gr.update();
}
vaVars.success = '' + (success != null);
})()
So, in the conversation OOTB using Incident, it uses the 'label name' to change the state with the update, not the value from the 'value' field.
Not sure what it does not like about how it is set up now, and make it return 0.
Ideas?
Cheers,
-Rob

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2020 11:01 AM
Ah nice, the script is executed, the sys_id is valid.
Can you also debug "vaVars.awaiting_acceptance_state"?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field