How to set a default choice for any field on a HR Case when a Chat Agent clicks on "Create HR Case"?

nirwan_ritik
Tera Contributor

As a Chat Agent, when I create a HR Case for a user by clicking "Create HR Case" in the Agent Workspace, I want to set the default value of the Source field of HR Case record to "Chat".
Please guide me how to achieve this.

Thanks 🙂

3 REPLIES 3

msd93
Kilo Sage

Hi @nirwan_ritik 

 

Try editing the existing "Create HR Case" UI Action or create a new ui action with below script:


// Set the default value for the "Source" field to "Chat"
current.source = 'Chat';

// Create the HR Case
var newHRCase = new GlideRecord('hr_case');
newHRCase.initialize(); // Initialize a new HR Case record
newHRCase.source = 'Chat'; // Set the "Source" field of the new HR Case record to "Chat"

// Insert the new HR Case record
var newHRCaseID = newHRCase.insert();

// Redirect to the newly created HR Case form
action.setRedirectURL('/nav_to.do?uri=hr_case.do?sys_id=' + newHRCaseID);

 

Hope this helps you.

Hi @msd93, thanks for the reply

Below is the code present in existing "Create HR Case" UI Action. Can we achieve my requirement somehow here only?

 

function onClick() {
    var USER = g_form.getValue('opened_for');
    var NEW_RECORD = '-1';
    var TABLE_HR_CASE = 'sn_hr_core_case';
    var PARENT_TABLE = g_form.getTableName();
    var PARENT_SYS_ID = g_form.getUniqueValue();
    g_aw.openRecord(TABLE_HR_CASENEW_RECORD, {userId: USER, subjectPersonIdOnCase: USER, parentTable: PARENT_TABLE, parentSysId: PARENT_SYS_ID});
}

Hi @nirwan_ritik 

 

Try adding a variable like var source = 'chat';//prvoide value of chat

and modify below line by appending the source variable:

g_aw.openRecord(TABLE_HR_CASENEW_RECORD, {userId: USER, source:source,subjectPersonIdOnCase: USER, parentTable: PARENT_TABLE, parentSysId: PARENT_SYS_ID});

 

Hope this works.