I need help on Incident form Resolve time issue

MK21
Tera Contributor

Hi I have question about incident form

 

after resolved the incident 

 

1) Resolved time is showing seconds, we need to show as Minutes/hours 

2) after Incident is resolved timer is running , we need to stop automatically after the incident is resolved

 

i will paste the image which i need help

 

find_real_file.png

 

1 ACCEPTED SOLUTION

Can you share your code which you have written?

Also can you make sure you have replace the correct value of State and Field Name in the script above, in case if you have a different value other than OOB.

My script works pretty well in my PDI which is an OOB instance.

Please share your code, state value of Resolved, and back end name of field of Time worked which you are trying to pause and I can assist you further.

I have tested again and is working correctly. See my screenshot below the timer is paused

find_real_file.png

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

7 REPLIES 7

shloke04
Kilo Patron

Hi,

I don't think there is any field named as "Resolve Time" on Incident or Task table. Assuming this is a custom field and you are setting this field in Seconds and now you need to convert this Seconds to Minutes and hours.

Within the same script where you are populating this field you need to update the same script with logic shown below:

var dur = 1036019; // This value will be replace with your seconds the way you are currently calculating it
var h = Math.floor(dur / 3600);
var m = Math.floor(dur % 3600 / 60);
var s = Math.floor(dur % 3600 % 60);
var finalis=h +':'+m+':'+':'+s;
gs.info(finalis);

Result:

find_real_file.png

So you can set this value in your String type field named as Resolve Time shown above in your screenshot.

Now for your Second Requirement, write an On Load Client Script on Incident table and use the Script as below:

function onLoad() {
    //Type appropriate comment here, and begin script below
    var status = g_form.getValue('state');
    if (g_form.getElement('time_worked') && ['6'].indexOf(status) >= 0) {
        toggleTimer('time_worked', '00:00:00');
        g_form.setReadOnly('time_worked', true);
    }

}

function toggleTimer(fieldName, timerVal) {
    try {
        //Get the necessary timer elements for fieldName given
        var timerEl = $('element.' + g_form.tableName + '.' + fieldName);
        var timerIcon = $('link.' + g_form.tableName + '.' + fieldName);
        if (timerEl != null) {
            //Make sure script does not break if field not present
            var timerPause = timerEl.select('input[id*=paused]')[0];

            //Toggle the timer
            if (timerPause.value == 'false') {
                timerPause.value = 'true';
                timerIcon = $('link.' + g_form.tableName + '.' + fieldName);
                timerIcon.removeClassName('icon-stop');
                timerIcon.addClassName('icon-play');
            } else {
                timerPause.value = 'false';
                timerIcon.removeClassName('icon-play');
                timerIcon.addClassName('icon-stop');
            }
        }
    } catch (e) {}
}

Result:

This is working correctly in my instance tested with both positive and negative scenario. Also if you want to pause the timer in future for other states, you just need to include that State choice value along with 6 i.e. for Resolved separated by comma in case you need it in future.

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

MK21
Tera Contributor

Hi 

i pasted your code it showing like this , pause button is not coming but the running time is going on it was not stopped,

 

find_real_file.png

Can you share your code which you have written?

Also can you make sure you have replace the correct value of State and Field Name in the script above, in case if you have a different value other than OOB.

My script works pretty well in my PDI which is an OOB instance.

Please share your code, state value of Resolved, and back end name of field of Time worked which you are trying to pause and I can assist you further.

I have tested again and is working correctly. See my screenshot below the timer is paused

find_real_file.png

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

MK21
Tera Contributor

I used the same script which you posted here and Resolved state value is 6 and field name is 

time_worked