When the user is starting the time on a Work Order using a timer, I want to update the Assignment to "STARTED" and then once the user taps on the timer to stop the time, if they use the "COMPLETE WORK" option, then I want to update the Assignment to "COMPLETE". I am having issues with the second piece of code saving the assignment status change to the database. Has anyone else ever updated Work Order Assignments?
This piece of code in the file js.application.handlers.StopTimerHandler.js works to complete the Assignment. NOTE: There are errors when going right to "COMPLETE" from "ASSIGNED" for "BMXAA4636E - The finish date must be later than the schedule date" and that is why I am trying to set the Assignment to "STARTED" when the user first starts the timer.
completeWorkAssignmentHandler: function(eventContext){
var woTimer = eventContext.getCurrentRecord();
var actualassignSet = eventContext.application.getResource("workOrder.assignmentlist");
// run other pause work tasks first
this.pauseWorkHandler(eventContext);
// loop over all of the assignments, we only want to update the one assignment that is for the user
// and not the ones that are craft or anything else this goes from STARTED -> COMPLETE
for(var i=0;i<actualassignSet.count();i++){
var assign = actualassignSet.getRecordAt(i);
// if the assignment is assigned to the user and the status is started, then we can complete that
if(actualassignSet.getRecordAt(i).get('laborcode') == woTimer.get('labor') && actualassignSet.getRecordAt(i).get('status') == 'STARTED'){
// set the new status here
assign.set('status','COMPLETE');
}
}
}
So, I tried to add code that will update the Assignment from "ASSIGNED" to "STARTED", and this code works as far as it updates the Assignment and I can see the updated data in the debugger, but it never commits to the database.
SetAssignmentToStarted: function(eventContext){
// get variables that we needed
var userLC = eventContext.actuallaborlist[0].laborcode;
// loop over all of the assignments, we only want to update the one assignment that is for the user
// and not the ones that are craft or anything else this goes from ASSIGNED -> STARTED
for (var i = 0; i < eventContext.assignmentlist.length; i++) {
// if the assignment is assigned to the user and the status is assigned, then we can complete that
if (eventContext.assignmentlist[i].laborcode == userLC && eventContext.assignmentlist[i].status == 'ASSIGNED')
// set the status on this record to started
eventContext.assignmentlist[i].status = 'STARTED';
}
}
},
Any suggestions or ideas?
Scott
------------------------------
Scott Patterson
SMS
------------------------------
#MaximoAnywhere#Maximo#AssetandFacilitiesManagement