SLA - that ends on the first working day of the next month at 08:30 AM?

Augustohenri01
Tera Expert

Hi guys, could someone help me, how can I create an SLA that ends on the first working day of the next month at 08:30 AM?

1 ACCEPTED SOLUTION

Augustohenri01
Tera Expert

Thanks for the replies, what did the trick was to create a Relative Duration:

 

(function() {

    var startDateMs = calculator.startDateTime;

	
    var retorno = verificaDiaPrimeiro(startDateMs);
    if (retorno) {
        //Criar o calculo para o mesmo dia
		var dateTime = new GlideDateTime(startDateMs);
		current.planned_end_time = dateTime.getDate() + " 10:00:00";
    }
    if (!retorno) {
			senaofordiautil(startDateMs);
        //utilizar a segunda função para calcular o primeiro dia util do proximo mês
    }


    function verificaDiaPrimeiro(startTime) {


        var startDate = new GlideDateTime(startTime).getLocalDate();

        var mes = startDate.getMonthNoTZ();
        var ano = startDate.getYearNoTZ();
        var dia = startDate.getDayOfMonthNoTZ();

        var diasAnterioresUteis = 0;

        if (dia != 01) { //Vai verificar se exitem dias úteis antes do dia que está na data

            for (var i = dia - 1; i > 0; i--) {
                var grData = ano + '-' + mes + '-' + i;
                var diaAtual = new GlideDateTime(grData);
                // Verifica se o dia é um dia útil (segunda a sexta-feira)
                var diaSemana = diaAtual.getDayOfWeekUTC();
                if (diaSemana !== 7 && diaSemana !== 6) {
                    diasAnterioresUteis++;
                }
            }

        }

        if (dia == 01 || diasAnterioresUteis == 0) { //vai verificar se é dia útil

            var day = startDate.getDayOfWeekUTC();

            if (day == 7 || day == 6) { //sabado ou domingo

                return false;

            } else {
               

                var time = new GlideDateTime(startTime).getLocalTime();
                var gt = time.getTime();
                var timeStr = gt.getByFormat('HH:mm:ss'); // 24 hour format
                var split = timeStr.split(":");
                
                if (split[0] < "09") {

                    return true;

                } else {
					
                    return false;
                
				}

            }

        } else {

            return false;

        }

    }

    function senaofordiautil(start_time) {

        var startDateTime = new GlideDateTime(start_time);
        var startTime = new GlideDateTime().getLocalTime().getByFormat('HH:mm:ss');
       
      
        //Cria um novo objeto
        var sentDateTime = new GlideDateTime(startDateTime);
        //Pega o número de dias no mês
        var diasInMonth = sentDateTime.getDaysInMonth();
        //Pega o dia atual
        var sentDay = sentDateTime.getDayOfMonth();
        //Cria um novo objeto
        var firstOfMonth = new GlideDateTime(sentDateTime).getLocalDate();
        //pega o dia atual e diminui menos 1 e deixa ele negativo
        firstOfMonth.addDaysLocalTime(-1 * (sentDay - 1));
        //adiciona o proximo mês na data
        firstOfMonth.addMonthsUTC(1);

        var data = firstOfMonth.getDisplayValue() + " " + "10:00:00";


        var gdt = new GlideDateTime();
        gdt.setDisplayValue(data, "dd/MM/yyyy HH:mm:ss");

		if(gdt.getDayOfWeekUTC() == 6 || gdt.getDayOfWeekUTC()==7){
        do {
            gdt.addDaysUTC(1);
        } while (gdt.getDayOfWeekUTC() == 6 || gdt.getDayOfWeekUTC() == 7);
		}
		
		var dateTimeForField = new GlideDateTime(gdt.getDate());
		
		//calculator.calcRelativeDueDate(startDateTime.getDate,dateTimeForField,"10:00:00");
    current.planned_end_time = dateTimeForField.getDate() + " 10:00:00";
	}

})();

 

View solution in original post

9 REPLIES 9

Badal Khojare
Mega Sage
Mega Sage

Hi @Augustohenri01 ,

Please check this link: https://docs.servicenow.com/en-US/bundle/vancouver-it-service-management/page/product/service-level-...

 

 

Please Mark My Response as Correct/Helpful if it helped.
Regards,
Badal Khojare
Community Rising Star 2023

Hi @Badal Khojare, Thank you for your reply.

AndersBGS
Tera Patron
Tera Patron

Hi @Augustohenri01 ,

 

as far as I recall, there is no option for what you’re looking for, as this is not the purpose of SLA. An SLA is more a specified timeframe under some defined conditions. You’re requirement does not have a specified timeframe as task open on 1 of October and task open on the 30th October, should end at the same time.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Hi @AndersBGS , I agree with your statement, but it was the client's request