Integrate the Time Tracker application into the portal
Best Answer
-
joivan_hedrick Cireson Consultant Advanced IT Monkey ✭✭✭I agree - it's pretty difficult to get analysts to remember to enter their time worked for each request. In the meantime, we do have some javascript that will automatically add time for each analyst as long as the page is open. It saves the time if they save/apply the page, and warns them that there are unsaved changes if they try to navigate away from the page. The code below works for incidents and could be extended to other WI types.
/* ------ Auto Add Billable Time to Incident ----- */
app.custom.formTasks.add('Incident', null, function (formObj, viewModel) {
formObj.boundReady(function () {
//If this is an analyst user, and an incident form, then start the timer to add BillableTime.
if (session.user.Analyst === 1 || session.user.IsAdmin === true) {
window.setCorrectingInterval(function() { addBillableTime(viewModel, 1); }, (1000 * 60 * 1), (1000 * 60 * 60 * 15) ); //update the time every 1 minute, max of 15 hours.
}
});
function addBillableTime(viewModel, addMinutes) {
var minute = parseInt(viewModel.get("Minute")); //save the current informaiton in the time control in case the user was editing time
var hour = parseInt(viewModel.get("Hour"));
viewModel.set("Minute", addMinutes); //change to the value we want to add
viewModel.set("hour", 0);
viewModel.view.billableTimeController.onAddClick(); //use the same billableTimeController that the interface uses.
viewModel.set("Minute", minute); //change back to original value
viewModel.set("hour", hour);
}
window.setCorrectingInterval = ( function( func, delay, maxRunningTimeInMs ) {
//this is similar to setInterval(), but corrects itself based on the PC time, so that it includes processing time
var instance = { };
//window.initialLoadTime = new Date();
function tick( func, delay, maxRunningTimeInMs ) {
if ( ! instance.started ) {
instance.func = func;
instance.delay = delay;
instance.startTime = new Date().valueOf();
instance.target = delay;
instance.started = true;
instance.maxRunningTimeInMs = maxRunningTimeInMs;
if (instance.maxRunningTimeInMs === undefined) {
instance.maxRunningTimeInMs = 0;
}
setTimeout( tick, delay );
} else {
var elapsed = new Date().valueOf() - instance.startTime,
adjust = instance.target - elapsed;
instance.func();
instance.target += instance.delay;
if (instance.maxRunningTimeInMs === 0 || (instance.maxRunningTimeInMs > 0 && elapsed < instance.maxRunningTimeInMs)) {
setTimeout( tick, instance.delay + adjust ); //Only run again if we have no max running time set, or our max running time has not been reached yet.
}
}
};
return tick( func, delay, maxRunningTimeInMs );
} );
});
/* ---- End Auto Add Billable Time to Incident --- */12
Answers
I'll give him a hug when I see him in a few weeks, that's just like a +12
@chris_ross - sounds good to me.
This block of code can be placed in the custom.js file, located in \inetpub\CiresonPortal\CustomSpace\ . After you paste the code in this file, save the file and hard refresh any incident page as an analyst. After a minute or so, time will automatically start adding for you on the Resolution tab.
For anyone interested in manually tracking time via the portal forms, here is a video for how to enable this in the Cireson Portal: https://player.vimeo.com/video/115604109
Way less exciting when you can automate, I know.
Can you update the script for the Portal v7?
It doesn´t work and i can´t find the problem.
I managed to get this to work with Service Requests too, just by copying the code block and changing the first line to app.custom.formTasks.add('ServiceRequest', null, function (formObj, viewModel).
I don't fully understand the code as my Javascript knowledge is pretty much none. What I've done seems to work for Service Requests but ONLY if you don't go to the Results tab before it's counted its first minute (after is fine). I have no idea why.
Does anyone have any ideas?
Hi, is there a version that works on portal 12 or now is the other solution?
@Marek_Lefek
Does this version not work on v12? What errors are you getting?