UI action should not be visible when DTASK are open

Naveen87
Tera Guru

Hello Developers,

 

I have a UI action called 'Next Phase' on Demand table. At Implementation phase if there are any DTASK open then 'Next Phase' button should not be visible. It's mandatory to close all attached task before closing the Demand.

Complex script include is already written. I'm not sure where & what code need to be added to make this run. 

Any help is appreciated.

UI action.

 

Naveen87_0-1726126908739.png

 

Script Include.

// Verification of multiple UI actions conditions.
    uiActionConditionChecks: function(name) {

        // UI action 'Next phase' button conditions.
        if (name == 'next_phase') {

            // Record is not valid or demand phase is 'Approval' or 'Evaluation
            // and Closure'
            if (!this.current.isValidRecord() || this.current.u_demand_phase == 5 || this.current.u_demand_phase == 7) {
                return false;
            }
            // Verify whether Minor demand is implemented.
            /*  if (this.current.u_demand_phase == 6 && this.current.u_change != ''&& this.current.u_change.u_closure_code!=''&& this.current.state == 5 ) {
				//gs.log("coming into 1st if log",'Prajnya99');
                return true;
            }*/
            if (this.current.u_demand_phase == 6 && this.current.u_change != '' && this.current.u_change.approval == 'rejected' && this.current.state == 11) {
                //gs.log("coming into 1st if log",'Prajnya99');
                return true;
            }

            if (this.current.u_demand_phase == 6 && this.current.u_change != '' && this.current.u_change.u_closure_code != '' && this.current.state == 11) {
                //gs.log("coming into 1st if log",'Prajnya99');
                return true;
            }
            if (this.current.u_demand_phase == 6 && this.current.state == 5) {
                //gs.log("coming into 1st if log",'Prajnya99');
                if (this.current.u_change != '' && this.current.u_change.u_closure_code == '') {


                    return false;
                } else if (this.current.u_change != '' && this.current.u_change.u_closure_code != '') {
                    return true;
                } else(this.current.u_change == '') {
                    return true;
                }

                
            }
            // Verify if all demand tasks are closed.
            if (!this._checkDemandTaskClosed(this.current.sys_id)) {
                return false;
            }

            // Verify whether Major demand is implemented.
            if (this.current.u_demand_phase == 6 && this.current.u_project != '' && this.current.state == 5 && this.current.u_demand_type != 'Minor Demand') {
                return true;
            }
            /*if(this.current.u_demand_phase == 6){
            	gs.log("coming into normal if log",'Prajnya99');
            	return true;
            }*/
            // Phase is 'Collection', state is 'Draft', role is demand reporter
            // and created by is equal to the user name.
            if (this.current.u_demand_phase == 1 && this.current.state == 0 && gs.hasRole('demand_reporter')) {
                return true;
            }

            // Phase is 'Collection', state is 'Draft' and role is
            // 'Coordinator'.
            if ((this.current.u_demand_phase == 1 && this.current.state == 0) && (gs.hasRole('demand_nsn_coordinator') || gs.hasRole('demand_si_coordinator'))) {
                return true;
            }

            // Phase is 'Logging', state is 'New' or 'Active' and role is
            // 'Coordinator'.
            if (this.current.u_demand_phase == 2 && this.current.assigned_to != '' && this.current.state == 5 && (gs.hasRole('demand_nsn_coordinator') || gs.hasRole('demand_si_coordinator'))) {
                return true;
            }

            // Phase is 'Business Analysis', state is 'Active' and role is 'NSN
            // coordinator'.
            if (this.current.u_demand_phase == 3 && this.current.state == 5 && this.current.assigned_to != '' && gs.hasRole('demand_nsn_coordinator')) {
                return true;
            }

            // Phase is 'Technical Analysis' or 'Implementation', state is
            // 'Active' and role is 'SI coordinator'.
            if (this.current.u_demand_phase == 4 && this.current.assigned_to != '' && this.current.state == 5 && gs.hasRole('demand_si_coordinator')) {
                gs.log("coming into last but one if log", 'Prajnya99');
                return true;
            }
            if (this.current.u_demand_phase == 4 && this.current.assigned_to == '' && this.current.state == 2 && gs.hasRole('demand_si_coordinator')) {
                gs.log("coming into last one if log", 'Prajnya99');
                return true;
            }

        }

 

Demand Phase & Open DTASK. Still UI button is visible.

Naveen87_1-1726127032249.pngNaveen87_2-1726127096008.png

 

Choice Values.

Naveen87_3-1726127150215.pngNaveen87_4-1726127170633.pngNaveen87_5-1726127181102.png

 

 

3 REPLIES 3

Naveen87
Tera Guru

I wrote this line of code but isn't working. 

Not sure if the placement is right.

Naveen87_0-1726127637215.png

 

Change 'alert' to gs.log, and align the lines with the block above it.  It's hard to tell if this is nested in another if, or just within the 'next phase' block.  You will want an else { return false; } block to hide the button.  Add another log right before this new if statement, and one in the else block, then you should be able to see if it is making it to this block and if the conditions are being met.   

I found this function & as per this. It should validate.

_checkDemandTaskClosed: function(sysID) {

		var rowCount = 0;		   
		var grTask = new GlideAggregate('u_demand_task');
		grTask.addQuery('parent', sysID.toString());
		grTask.addQuery('state', '!=', 3);
		grTask.addQuery('state', '!=', 5);			   
		grTask.query();
		grTask.addAggregate('COUNT');
		grTask.query();
		if(grTask.next())
			rowCount = grTask.getAggregate('COUNT');

		if (rowCount > 0) {
			return false;
		} else {
			return true;
		}