We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

HR Life cycle event activity set advanced trigger

SaiVikasR
Tera Contributor

Hi All,

I am using advanced script to check if last day of is today is true trigger activity set. I have checked script with adding logs I am unable to get last day of work, I can see parent HR case.  Last day of work updated with todays date.

 var termReason = String(parentCase.getValue('u_reason_for_termination')).toLowerCase();
    if (termReason == 'attend') {
        return false;
    }
    // Immediate termination check
    var isImmediate = (parentCase.u_immediate_termination == true || parentCase.u_immediate_termination == 'true');
    // Last day logic
    var isLastDay = false;
    var lastDayRawValue = parentCase.getValue('u_lastdayofwork');
    if (lastDayRawValue) {
        var today = new GlideDate();
        var lastDay = new GlideDate();
        lastDay.setValue(lastDayRawValue);
        // >= 0 means today OR past
        if (today.compareTo(lastDay) >= 0) {
            isLastDay = true;
        }
    }

    return (isImmediate || isLastDay);
2 REPLIES 2

abirakundu23
Giga Sage

Hi @SaiVikasR ,
- Is the last day work field on parent HR case or HR task ?
- One more thing "u_lastdayofwork" field should be Data/Time field ideally but in your code 
var lastDay = new GlideDate(); - this may be cause.

- Also check seems  Advance script executed before field value('u_lastdayofwork) update in HR case .

Please mark helpful & correct answer if it's worthy for you.

Tanushree Maiti
Tera Patron

Hi @SaiVikasR 

 

Can you try this . Post testing ,remove gs log.

 

 var termReason = String(parentCase.getValue('u_reason_for_termination')).toLowerCase();
    if (termReason == 'attend') {
        return false;
    }
    // Immediate termination check
    var isImmediate = (parentCase.u_immediate_termination == true || parentCase.u_immediate_termination == 'true');
    // Last day logic
    var isLastDay = false;
    var lastDayRawValue = parentCase.getValue('u_lastdayofwork');
    if (lastDayRawValue) {
        var today = new GlideDate();
        var lastDay = new GlideDate();
        lastDay.setValue(lastDayRawValue);
if (today.getDisplayValue() === lastDay.getDisplayValue()) 
{
          gs.info("Termination day is today! ");
          isLastDay = true; 
        } else
{
          gs.info("Today is not the termination day.");
      isLastDay = false;
        }
        //if (today.compareTo(lastDay) >= 0) {
           // isLastDay = true;
      //  }
    }
 
    return isLastDay;

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti