updating Create HR Case UI action in interaction record

kartikey
Tera Contributor

Hi Everyone,

There's a "Create HR Case" ui action on interaction record, which has a Workspace client script:

 

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_CASE, NEW_RECORD, {userId: USER, subjectPersonIdOnCase: USER, parentTable: PARENT_TABLE, parentSysId: PARENT_SYS_ID});
}



As far as i've looked into it 'g_aw.openRecord' is used to open an existing record, then how is this button creating a new record?

Further my requirement is that when a new record is created i wish to set few field values to it example, HR service, Source, assigned to etc. how do i implement this or update the UI action ?
Can someone please help me with this?

Thanks,
Kartikey

4 REPLIES 4

Ravi Gaurav
Giga Sage
Giga Sage

Hi @kartikey 

Here's an updated version of the onClick function that sets the hr_servicesource, and assigned_to fields:

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();

var parameters = {
hr_service: 'Your HR Service Value', // replace with the desired value
source: 'Your Source Value', // replace with the desired value
assigned_to: 'Your Assigned To Value' // replace with the desired value
};

g_aw.openRecord(TABLE_HR_CASE, NEW_RECORD, {
userId: USER,
subjectPersonIdOnCase: USER,
parentTable: PARENT_TABLE,
parentSysId: PARENT_SYS_ID,
parameters: parameters
});
}

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

If I click on the Create HR case  UIaction/button it's redirecting to the case creation page

kartikey_0-1724921435934.png

 

share your Script

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

No I mean, it's redirecting me to the case creation page, and if i create an HR case from here then its not setting the values we provided.