Need to populate time left filed incident form which is value of business left time from task_sla

Brahmi Pandla
Tera Guru

Hi

 

I have requirement  

 

We created a custom field time left form duration type, and now I want to populate this field with the business time left value from the task_sla table.

 

could you please any one suggest

4 REPLIES 4

Amit Gujarathi
Giga Sage
Giga Sage

Hi @Brahmi Pandla ,
I trust you are doing great.

Here's an example of how you can accomplish it:

  1. Create a new business rule or script include to perform the necessary calculations and updates.
  2. Retrieve the relevant record from the task_sla table based on the associated task.
  3. Calculate the business time left by subtracting the current time from the SLA's end time, taking into account any business hours or holidays.
  4. Update the custom field "Time Left" on the task record with the calculated value.
// Get the task_sla record for the associated task
var slaGR = new GlideRecord('task_sla');
slaGR.addQuery('task', current.task); // Replace 'current.task' with the appropriate field if needed
slaGR.query();

if (slaGR.next()) {
  // Calculate the business time left
  var endTime = new GlideDateTime(slaGR.getValue('end_time'));
  var currentTime = new GlideDateTime();
  var businessTimeLeft = gs.dateDiff(currentTime, endTime, true);

  // Update the custom field "Time Left" on the task record
  current.time_left = businessTimeLeft;
  current.update();
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi Amit,

 

Thanks for response , why we need calculate the business time left here, already businesstimeleft field  value is avaiable in task_sla table.

 

i want same value populate to time_left field

Hi Amit,

 

It's not working

Hi Amit,

 

Could you please  help on this