Resolving HR Cases via VA Chatbot

Rob Sestito
Mega Sage

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

find_real_file.png

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:

find_real_file.png

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

1 ACCEPTED SOLUTION

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 Roethof - seriously thank you for all your help with this! Truly helpful!

View solution in original post

25 REPLIES 25

Mark Roethof
Tera Patron
Tera Patron

Hi there,

How do the conditions on the transitions look like?

Try just to add some debugging. For example gs.info statements, within the while. Is the while even reached? Or is there already something wrong with your gliderecord query. So also debug the parms like vaVars.closed_complete_state, does this give the expected value?

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

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Hi there,

How do the conditions on the transitions look like?

Try just to add some debugging. For example gs.info statements, within the while. Is the while even reached? Or is there already something wrong with your gliderecord query. So also debug the parms like vaVars.closed_complete_state, does this give the expected value?

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

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

To verify:

You are performing this on sn_hr_core_case. Are you performing this new topic also in the Scoped App of that table? Or in global? If global, you might run into Security restricted (and so the GlideRecord already not giving result).

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

LinkedIn

That is a good point actually. I am doing this on the HR Virtual Agent scope. Would this need to be created in the HR Core scope?

And to try and reply to your first reply:

After the 'Get Cases' where I am hoping it finds the records, the three decisions are first just looking for the number of records found. So, the conversation is not coming to an error, it is passing through the 'No Cases Found' decision. Which is why I feel I am hitting the table incorrectly.

So, do you think it's due to the Scope I am creating this under?

find_real_file.png

Thanks,

-Rob