Restrict COMPLETE Status from options
About this task
This guide instructs you to disable the COMPLETE option until the following conditions are met:
- The work order must contain at least one work log entry;
- Must contain an actual labor entry (for current labor);
- If work type is different from PM, check for presence of asset and the existence of complete PCR (Problem, Cause, Remedy) entry;
- If work type is PM, no need to have an asset or PCR entry. In this customization, the COMPLETE option is removed from the status change lookups. The Work Order completion must be completed through the report page, if the conditions are met.
Procedure
Step 1: Add a boolean page state to the report_work page
<states id="jy5r4">[...]<state name="disableCompleted" value="false" type="boolean" id="trg_g8n3b"/></states>
Step 2: In the app.xml file, include the hidecompleted state to the disable condition on the button (p6aav)
<button slot="buttons" label="Complete work" kind="primary" id="p6aav" […]disabled="{page.state.disableCompleted || woDetailsReportWork.item.flowcontrolled || !app.checkSigOption(`${app.state.woOSName}.COMPWOBUTTON`)}"/>
Step 3: In the AppCustomization.js file, declare the dialogOpened method to handle the window opening event. The code inside
the method should contain the verification of the name of the dialog that was opened, the existence of the datasource and the confirmation of the current page before executing the filter, “item.maxvalue !== ‘COMP’”, insert the following logic in the method:
/*** dialogOpened handler filter out complete status when opened* @param {Object} obj* @param {Dialog} obj.dialog*/dialogOpened({dialog}) {// page name when dialog is openthis.app.log.d(TAG,`dialog ${dialog?.name} opened at ${this.app.currentPage.name} page`);
Step 4: Create a method to check if a given list contains full failure report (Problem, Cause and Remedy)
/*** Validates Problem, Cause and Remedy inside failure report list* @private* @param {Array} failureReport - failure report list.* @returns {boolean} Promise of an array of items.*/hasPCR(failureReport = []) {let hasProblem = false;let hasCause = false;
Step 5: Create the main method responsible to output if the a work order item can be completed based on the criteria discussed.
/*** Validation to allow completion. Validation is:* a. should have work Log comments* b. should have labor actuals* c. should have Problem Cause and Remedy codes IF Work Type is not in [PM] and there is an Asset on the record* This should only be called from report_work page* @param {Application} app* @returns {boolean}*/
Step 6: Apply validation using the previous method to update the state created.
/*** Enables/disables complete button from report work page based on complete validation* @param {Page} page* @param {App} app*/async addCompleteButtonValidation(page, app) {// Set disable before starting processing conditionpage.state.disableCompleted=true;// Get validation result
Step 7: Bind buttonValidation method to pageResumed lifecycle hook when it is the correct page.
pageResumed(page, app) {// Run validation for complete buttonif (app.currentPage.name === 'report_work' && page.name==='report_work') {this.app.log.d(TAG,'entering add completebuttonvalidation logic');this.addCompleteButtonValidation(page, app);}}