UI Action is not picking the condition

ABC6
Tera Contributor

Hello Team,
Ui Action is not picking up the condition where it calling script include , please help me to get this issue resolved
ideally it should skipped the Risk assesment for RFC change , poreviously it is working but not now 

ABC6_0-1746517834138.png

 

21 REPLIES 21

@ABC6 Ok, got it. In that case, you would need to have a look at RiskAssessment script include and checkRiskQuestions function to see why it is returning true.

 

It should return false ideally to not get alert message and proceed further.

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

ABC6
Tera Contributor
checkRiskQuestions:function(){
  var assessmentinstance = new GlideRecord('asmt_assessment_instance');
assessmentinstance.addQuery('task_id', this.getParameter('sysparm_sysid'));
assessmentinstance.query();

if (!assessmentinstance.next()) {
    // No record found, so return true
     gs.log('No assessment instance found for task_id: ' + this.getParameter('sysparm_sysid'));
    return true;
} else {
    // Record found, so return false
     gs.log('Assessment instance found for task_id: ' + this.getParameter('sysparm_sysid'));
    return false;
}

},

ABC6
Tera Contributor

Script is returning false for this

Ankur Bawiskar
Tera Patron
Tera Patron

@ABC6 

share that script include which is added in condition field

that should return true/false

If it returns true -> button is seen

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

isEnabled: function(current, step) {
        if(!current.isNewRecord() && current.approval == 'not requested' && (current.state == '1' || current.state == '2')){
            var workflow = new Workflow();
            var context = workflow.getContexts(current);
            if (context.next()) {
                var rfcStepContext = context.scratchpad.rfcStep;
                //Show Request Review/Request Approval button on existing record has the previous workflow version
                if(JSUtil.nil(rfcStepContext) && current.type == 'Normal'){
                    var isRFCApprovals = this.checkRFCApprovals(current.sys_domain.name, current.company.name);
                    var isRFCApprovalsRequested = this.isRFCApprovalsRequested(current.sys_id);
                    var technicalApprovals = context.scratchpad.showEditAdhoc;
                    var rfcApprovals = context.scratchpad.rfcApprovals;
                    var rfcGrpApprovals = context.scratchpad.rfcGrpApprovals;
                    //Check the current workflow step to show Request review button
                    if(step == 'Review'){
                        //Case 1: the workflow step is in RFC approval processing
                        if(isRFCApprovals && typeof rfcApprovals == "undefined" && typeof rfcApprovals == "undefined"){
                            return false;
                        //Case 2: the workflow step completed RFC approvals/without RFC approvals
                        }else if((isRFCApprovals && (rfcApprovals.length >= 0 || rfcGrpApprovals >= 0)) || !isRFCApprovals){
                            return (current.state == '1');
                        }
                    }else if(step == 'Approval'){//Check the current workflow step to show Request Approval button
                        //Case 1: the workflow step is in RFC approval processing
                        if(isRFCApprovals && typeof rfcApprovals == "undefined" && typeof rfcApprovals == "undefined"){
                            if(isRFCApprovalsRequested){//Don't show button when RFC approvals is generated.
                                return false;
                            }else//Show button when RFC approvals is not generated
                                return (current.state == '1');
                            //Case 2: the workflow step has RFC approvals is completed
                        }else if (isRFCApprovals && (rfcApprovals.length >= 0 || rfcGrpApprovals >= 0)){
                            //Disable Request Approval button when state is Draft or Review and this state is reverted on Request Review
                            if(typeof technicalApprovals == "undefined" && current.state == '1'){
                                return false;
                            }else if(current.state == '2'){//Enable button when state is Review
                                return true;
                            }
                        }else if(!isRFCApprovals){//Case 3: the workflow step is without RFC approvals
                            return (current.state == '2');
                        }
                    }
                }else if(JSUtil.notNil(rfcStepContext) || (JSUtil.nil(rfcStepContext) && current.type == 'Emergency')){//Show Request Review/Request Approval button on new normal change
                    if(step == 'Review')
                        return (current.state == '1' && rfcStepContext == step && current.type == 'Normal');
                    else if(step == 'Approval')
                        return (current.state == '2' || (current.state == '1' && rfcStepContext == step));
                }
            }
        }
        return false;
    },