HR Case Creation with Virtual Agent

nathandanek
Tera Contributor

Hi all,

 

I have been attempting to implement HR Case Creation into my VA through the OOTB topic block that comes with the HR Service Delivery Plugin, but I am struggling as there is no documentation on how to fill out the topic block or edit the scripts inside of it to customize it. I want to create an HR case and have fields already filled out based on the conversation had with the user and so I am attempting to edit the "create hr case" script that is inside the topic block.Screenshot 2023-11-27 at 11.05.17 AM.png

This is the code that the topic block contains:

(function execute() {
    var hrServiceId = vaInputs.hr_service.getValue();
    var caseTable = vaInputs.case_table.getValue();
    var questions = vaInputs.case_questions;
    if (!gs.nil(hrServiceId) && !gs.nil(caseTable) && !gs.nil(questions)) {
        questions = JSON.parse(vaInputs.case_questions);
      var additional_comments = {
            question: "Please provide additional comments for your case.",
            name: "additional_comments",
            answer: vaInputs.additional_comments,
            raw: vaInputs.additional_comments,
            answerDisplayValue: vaInputs.additional_comments
        }
        questions.push(additional_comments);
        var caseDetails = new sn_hr_va.hr_ChatbotUtils().createCaseWithHRService(hrServiceId, caseTable, questions);
        vaVars.case_sysid = caseDetails.sysid;
        if (vaVars.case_sysid) {
            vaVars.is_case_created = true;
            vaSystem.attachRecordToConversation(caseTable, caseDetails.sysid);
        }
        var gr = new GlideRecord('sn_hr_core_case');
        if (gr.get(vaVars.case_sysid)) {
            gr.work_notes = vaSystem.getTranscript();
            gr.update();
        }
    }
})()

I noticed that the code has the function "createCaseWithHRService()" that is fed some inputs and then, after it's created, the code then goes in and updates fields such as work_notes. What I attempted to do was this:

(Code Omitted for Readability, it is the same as the code in the previous sample)
        var caseDetails = new sn_hr_va.hr_ChatbotUtils().createCaseWithHRService(hrServiceId, caseTable, questions);
        vaVars.case_sysid = caseDetails.sysid;
        if (vaVars.case_sysid) {
            vaVars.is_case_created = true;
            vaSystem.attachRecordToConversation(caseTable, caseDetails.sysid);
        }
        var gr = new GlideRecord('sn_hr_core_case');
        if (gr.get(vaVars.case_sysid)) {
            //gr.work_notes = vaSystem.getTranscript();
            gr.opened_for = gs.getUserID();
            gr.subject_person = gs.getUserID();
            gr.topic_category = "Benefits";
            gr.topic_detail = "Retirement Savings Plan/401(k)";
            gr.short_description = hrServiceId + " case for " + gs.getUserID();
            gr.assignment_group = "Employee Services"
            gr.update();
        }
    }
})()

I attempted to update further fields with information based on the topic and the current user but it just gave me an error and did not work. My question is this: is this where I should be doing this in the code, or should I be putting these variables into the "createCaseWithHRService" function? Is there any documentation that says what I can pass into this function?

 

Another thing to note is that this topic block did not work for me OOTB without any changes to the scripts or anything so there may also be another problem that I do not know about that is preventing this topic block from working. 

 

Please do not link me to Virtual Agent for HR Service Delivery as I have already read through this and it was no help as there is not a single piece of information about the create HR case topic block besides a mention that it exists.

 

Thanks,

Nathan

1 ACCEPTED SOLUTION

Aaron6
Giga Expert

ServiceNow: Write documentation for your basic Virtual Agent functions, especially if you're charging a premium. The same question was asked in 2022 with no answer. Case creation is not an edge case.

 

I looked into this, I have a similar use case.

 

Yes, case questions is a JSON object, but a developer has no indication of what the expected structure is. 

It also must be a string (with no newlines, otherwise ServiceNow will throw a generic syntax error.)

 

Your answer is in unfortunately buried in code:

Script Include: hr_ChatbotUtils

MethodcreateCaseWithHRService()

 

Case questions (from what I understand without reading through the entire file) populates your case description, and adds fields to your case XML before submission. It's practically the only OOB way to create cases that are not standard core hr cases, since they often require fields populated before submission.

 

How should it look:

'[{"question": "<display name of the field to be added>", "name": "<column name of the field to be added>", "mappingField": "<column name of the field to be added>", "answer": "<display value of the field to be added>", "raw": "<provided value of the field to be added>", "answerDisplayValue": "<display value of the field to be added>"}]'
 
What do these do? Not sure, but generally:
question: Displays in the case description.
name: No clue what this actually does.
mappingField: This maps the raw value to the actual case.
answer: No clue what this actually does.
answerDisplayValue: Displays to the right of the "question" in the case description
 
mappingField is what you need

View solution in original post

3 REPLIES 3

Neel Patel
Tera Guru

Hi Nathan,

 

It seems that the createCaseWithHRService, uses a JSON object to populate fields in HR.

Have you tried creating a JSON object and passing in the parameters?

Yeah, I have tried that. For my client, when they are creating an HR case manually, their fields are auto populated based on the HR Service provided. Therefore, I am confused as to what Case Questions is doing in this instance? Do fields not auto populate based off business rules when creating an HR Case through this topic block? What parameters should I be passing into this field, as I cannot leave it blank according to the topic block?

Aaron6
Giga Expert

ServiceNow: Write documentation for your basic Virtual Agent functions, especially if you're charging a premium. The same question was asked in 2022 with no answer. Case creation is not an edge case.

 

I looked into this, I have a similar use case.

 

Yes, case questions is a JSON object, but a developer has no indication of what the expected structure is. 

It also must be a string (with no newlines, otherwise ServiceNow will throw a generic syntax error.)

 

Your answer is in unfortunately buried in code:

Script Include: hr_ChatbotUtils

MethodcreateCaseWithHRService()

 

Case questions (from what I understand without reading through the entire file) populates your case description, and adds fields to your case XML before submission. It's practically the only OOB way to create cases that are not standard core hr cases, since they often require fields populated before submission.

 

How should it look:

'[{"question": "<display name of the field to be added>", "name": "<column name of the field to be added>", "mappingField": "<column name of the field to be added>", "answer": "<display value of the field to be added>", "raw": "<provided value of the field to be added>", "answerDisplayValue": "<display value of the field to be added>"}]'
 
What do these do? Not sure, but generally:
question: Displays in the case description.
name: No clue what this actually does.
mappingField: This maps the raw value to the actual case.
answer: No clue what this actually does.
answerDisplayValue: Displays to the right of the "question" in the case description
 
mappingField is what you need