Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Order guide

Reddy39
Tera Expert

Order guide :- Onboarding

There are multiple catalog items configured through rule base in that only for some items Validation task will generate

Only for SCTASK short description that starts with "Validation Task..." 

Prohibit Close Skipped of validation task for Onboarding Request catalog item. Pop up message: “Only Close Incomplete or Close Complete Allowed”

 

Please help me how to achieve this 

5 REPLIES 5

MaxMixali
Kilo Sage

omplete Solution with Request Item Check

If you need to verify this is specifically for the "Onboarding Request" catalog item:

Client Script (onChange):

 
 
javascript
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    
    // Check if this is a validation task
    var shortDesc = g_form.getValue('short_description');
    
    if (shortDesc && shortDesc.indexOf('Validation Task') === 0) {
        
        // Get parent request item
        var reqItemId = g_form.getValue('request_item');
        
        if (reqItemId) {
            // Check if parent is Onboarding Request
            var ga = new GlideAjax('OnboardingTaskValidator');
            ga.addParam('sysparm_name', 'isOnboardingRequest');
            ga.addParam('sysparm_request_item', reqItemId);
            ga.getXMLAnswer(function(answer) {
                
                if (answer === 'true') {
                    // This is an onboarding request validation task
                    var stateLabel = g_form.getDisplayBox('state').value;
                    
                    if (stateLabel === 'Closed Skipped') {
                        g_form.setValue('state', oldValue);
                        g_form.showErrorBox('state', 'Only Close Incomplete or Close Complete Allowed');
                        alert('Only Close Incomplete or Close Complete Allowed for Validation Tasks');
                    }
                }
            });
        }
    }
}

Script Include:

  • Name: OnboardingTaskValidator
  • Client callable: true
 
 
javascript
var OnboardingTaskValidator = Class.create();
OnboardingTaskValidator.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    
    isOnboardingRequest: function() {
        var reqItemId = this.getParameter('sysparm_request_item');
        
        var ritm = new GlideRecord('sc_req_item');
        if (ritm.get(reqItemId)) {
            var catItem = ritm.cat_item.getDisplayValue();
            
            // Check if catalog item is "Onboarding Request" or use sys_id
            if (catItem === 'Onboarding Request' || catItem.indexOf('Onboarding') !== -1) {
                return 'true';
            }
        }
        return 'false';
    },
    
    type: 'OnboardingTaskValidator'
});





Hello i hope that can help

If you find this answer useful, please mark it as solution accepted/helpful

Massimiliano Micali