The CreatorCon Call for Content is officially open! Get started here.

How can I get rejected HR Case list- which are changed from awaiting acceptance to work in progress

bhuvana7
Tera Contributor

Hello @all,

I have a requirement to get the list of rejected cases - so for this I have created a new field(Case has been rejected=true)  and created a business rule to update the rejected status. But I want the list of rejected HR Case numbers for old cases also.

How the case can be rejected -> we can identify this -> when a state changes from 'awaiting acceptence' to 'work in progress'.

So please help me to get the solution for this to get the list of rejected cases.

Below is the UI Action we are using for rejection -> when a user clicks on Reject Completion -> A dialog will appear -> by providing a reason in dialog box -> a user can reject the case.

 

 

function rejectCompletion() {
    if (g_form.getValue('state') == 20) {
        //if state has not changed
        var sysId = typeof rowSysId == 'undefined' || rowSysId == null ?
            g_form.getUniqueValue() : rowSysId;
        var dialogClass = GlideModal ? GlideModal : GlideDialogWindow;
        var dialog = new dialogClass('sn_hr_core_HR Comment Dialog');
        var msg = new GwtMessage().getMessage('Provide a reason for reject completion');
        dialog.setTitle(msg);
        dialog.setPreference('sysparm_task_sys_id', sysId);
        dialog.setPreference('sysparm_task_table', 'sn_hr_core_case');
        dialog.setPreference('sysparm_ok_method_name', 'rejectCompletion');
        dialog.setPreference('sysparm_is_comment', 'true');
        dialog.on('hrComentDialogSucess', function() {
            //g_form.setValue('u_case_has_been_rejected', true);
            dialog.destroy();
            gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay');
        });
        dialog.render();
        return;
    } else {
        //if state has changed show error message
        g_form.addErrorMessage(getMessage("The state of the case has been updated recently. Please refresh the page."));
    }
}​

 

 

 

bhuvana7_0-1707989833086.png

 

bhuvana7_2-1707989907920.png


Kindly help me with your suggestions - @Rob Sestito @Eswar Chappa @Ankur Bawiskar 
Thank you in advance.

kind regards
bhuvana

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Srinivasa1
Tera Expert

@bhuvana7, I have made some modifications to the script. Could you please check the changes?

Additionally, I would like to ask that you run the "fix script" within the HR Core scope to ensure that HR cases are accessible.

var gr = new GlideRecord('sys_history_line');
gr.addQuery('label=State^old=Awaiting Acceptance');
gr.query();
while (gr.next()) {
var historyId = String(gr.set.id);
 
 
var hrCaseGr = new GlideRecord('sn_hr_core_case');
hrCaseGr.addQuery('sys_id', historyId);
hrCaseGr.query();
if (hrCaseGr.next()) {
gs.info('test1');
hrCaseGr.setValue('rejected_field', true);
hrCaseGr.update();
gs.info('HR Case Updated - Rejected: ' + hrCaseGr.getValue('case_number'));
} else {
gs.error('HR Case Not Found for History ID: ' + historyId);
}
}

View solution in original post

6 REPLIES 6

Srinivasa1
Tera Expert

Typically, for cases that have been rejected, updates are done in the comments section, making it challenging to retrieve specific data. However, utilizing the audit trail allows us to access the most recently rejected cases. To do so, please visit the following link:

https://<instance-name>.service-now.com/sys_history_line_list.do?sysparm_query=label%3DState%5Eold%3...

This link grants access to the history of state changes, enabling us to identify and review recent rejections based on the historical data your instance retains. The field set within will provide information about which record has been rejected.

Thank you @Srinivasa1 ,
It helped me, but can you help with the script for this?
Below is the history I can see - I can see the HR Case number, so based on this I need to update a new rejected field with true value in the HR Case Table.

bhuvana7_0-1708494739398.png

Somehow, I tried below script, but it is going out to else condition - working till  'gs.info('test');'

var gr = new GlideRecord('sys_history_line');
gr.addQuery('label=State^old=Awaiting Acceptance^new=Work in Progress');
gr.query();
while (gr.next()) {
var historyId = gr.getDisplayValue('set');
gs.info('history id:' +historyId);
var hrCaseGr = new GlideRecord('sn_hr_core_case');
hrCaseGr.addQuery('number', historyId);
hrCaseGr.query();
gs.info('test');
if (hrCaseGr.next()) {
gs.info('test1');
hrCaseGr.setValue('rejected_field', true);
hrCaseGr.update();
gs.info('HR Case Updated - Rejected: ' + hrCaseGr.getValue('case_number'));
} else {
gs.error('HR Case Not Found for History ID: ' + historyId);
}
}

 

Kindly help me with the script, I will be thankful.
@Srinivasa1 @Rob Sestito @Eswar Chappa @Ankur Bawiskar @
Kind Regards
Bhuvana

Srinivasa1
Tera Expert

@bhuvana7, I have made some modifications to the script. Could you please check the changes?

Additionally, I would like to ask that you run the "fix script" within the HR Core scope to ensure that HR cases are accessible.

var gr = new GlideRecord('sys_history_line');
gr.addQuery('label=State^old=Awaiting Acceptance');
gr.query();
while (gr.next()) {
var historyId = String(gr.set.id);
 
 
var hrCaseGr = new GlideRecord('sn_hr_core_case');
hrCaseGr.addQuery('sys_id', historyId);
hrCaseGr.query();
if (hrCaseGr.next()) {
gs.info('test1');
hrCaseGr.setValue('rejected_field', true);
hrCaseGr.update();
gs.info('HR Case Updated - Rejected: ' + hrCaseGr.getValue('case_number'));
} else {
gs.error('HR Case Not Found for History ID: ' + historyId);
}
}

bhuvana7
Tera Contributor

Hi @Srinivasa1 ,

Thank you for your support on this issue, it is working and I executed it in 'fix script'.

Kind Regards,
Bhuvana