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

Hi @bhuvana7 
Also, please include the following line in the code:

hrCaseGr.setWorkflow(false); before the line hrCaseGr.update();

Just to ensure it wont trigger any BR's or flows.

Thank you @Srinivasa1 , Updated.

Kind Regards
Bhuvana