Mark rejected HR cases

Lemajeur
Mega Expert

Hi folks,

 

Is there a way to mark all rejected hr cases in a single script? I am thinking to create a True/False field which will turn to true when a user clicks on ˇreject completionˇ or no in the HR portal. 
I wanted to write a business rule on sn_hr_core_case table, but since so many tables are inherited from it, I guess that it will not work. 

 

Any pointers on how to achieve this? 

1 ACCEPTED SOLUTION

Rob Sestito
Mega Sage

Hey Lemajeur,

So for the Business Rule way, I don't see why you could not use that with a true/false field. When Case is rejected in HR, it typically goes from Awaiting Acceptance State to WIP State (for us it does anyway).

I built a BR and True/False field on the HR Case Core Table (then within the other tables you would be using this for, you just need to configure the layout for their form to add the new field where you want it).

Here is what I did, and it works each time any case changes from Awaiting Acceptance to WIP (which constitutes as a "case being rejected for completion"):

find_real_file.png

 

find_real_file.png

find_real_file.png

 

However, if you are looking to report off of something like this, you may want to build something additional to move this field back to false when the Case is moved into Awaiting Acceptance again (or just have the Assigned To trained to uncheck the box when they attempt to resolve again).

Hope this helps - Let me know if it does or does not work for you. Maybe we can brainstorm more or another option.

Cheers!

-Rob

View solution in original post

13 REPLIES 13

Hi Rob Sestito,


Thank you for your solution, it was helped me.

But I also want the same update to old records - I need to see the rejected cases list for past records as well. Please provide any suggestions.

Thank you in advance.


Thanks 
Bhuvana

Hey @bhuvana7 - 

 

To do this to old records that have already gone through the State field flow process, I would imagine you would want to create a Fix Script/Background script to set the field for old cases. Because you would not want to go through changing all the old records from active = false to active = true, only to set them back to active = false again.

So, I would say to create a Fix Script that can run in the background and update all the old records you were referring to. I would get the old records you want into a List View, copy the query, and use that as an encoded query within your Fix Script. Test in a sub-prod of course, and be sure the script matches your list view of those records.

 

You could put a log message within the script and comment out the lines that will actually do the updating to the records. That way you can check the number of records the script finds against your list view of records you know you want to update.

 

Hope this helps!

Cheers,

-Rob

Thanks @Rob Sestito for the prompt response.

Could you please help me with the sample fix script, that will help me to debug more.

Thank you in advance.

You're welcome @bhuvana7 !

And the sample script would be something like this (Don't forget to change the script according to your instance, like the field name(s)😞

// Define the Fix Script
(function () {
    // Define the query to retrieve HR Cases where approval state is rejected
    var hrCaseGr = new GlideRecord('sn_hr_core_case');
    hrCaseGr.addQuery('approval', 'rejected');
    hrCaseGr.query();

    // Count the number of records that match the query
    var recordCount = hrCaseGr.getRowCount();
    gs.info("Found " + recordCount + " HR cases with approval state rejected.");

    // Loop through the records if there are any
    if (recordCount > 0) {
        while (hrCaseGr.next()) {
            // Update the custom true/false field to true
            hrCaseGr.setValue('custom_true_false_field', true);
            hrCaseGr.update();
            gs.info("Updated HR case " + hrCaseGr.number + ".");
        }
    } else {
        gs.info("No HR cases found with approval state rejected.");
    }
})();

 

Where you see "custom_true_false_field" is where you would add in your actual custom field that you want to update to be true. This script is just checking if the cases on the hr case table have an Approval State of Rejected. So that is another field you want to make sure that you have correct in the script. If you are using the OOTB Approval State field, then this should be correct.

 

Also you will notice the gs.log statements. Usually when running a Fix Script, we want to make sure we match the amount of records from your list view I recommended getting before. What you will want to do is, comment out the hrCaseGr.setValue and hrCaseGr.update fields first, and then run the script. This will let the script run, pull the gs.info statements for us so you can match them against the number of records in your list view. Once you can confirm and are confident, then just uncomment those two lines and run it again.

 

Remember, do this in a sub-prod first to test appropriately . Better to make a mistake in a sub-prod than the actual prod.

 

Hope this helps, and let me know how the testing goes!

Cheers,

-Rob

HI @Rob Sestito ,

We dont have any approval field for to track the rejected cases, then on what basis I can query the records for old HR Cases?

Kindly let me know your suggestions on this.
Kind Regards
Bhuvana