Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

UI action configuration on SOW view

AkshitG90438384
Kilo Explorer

Hi Fellas, 

 

I hope you all are doing well. 

I am recently stuck with a requirement and would love some insights, solutions on it. 

 

There are UI actions on Change Request that are Close or Request Approval. Requirement was to make those button disabled if the assignment group is SAP and the logged in user is not Angela. 

If the logged in user is Angela and assignment group is SAP so she can access those UI actions to change the states of the Change Request. 

 

It was easy to configure UI actions for native view but when it comes to SOW view (I am finding hard time) 

I will attach screenshots and scripts for the reference. 

 

Screenshot 2026-09-30 114242.pngScreenshot 2026-09-30 114202.pngScreenshot 2026-09-30 114110.png

 

The scripts Im using for Close UI action is

function moveToClosed() {
    if (g_user.hasRole('admin')) {
        g_form.setValue("state", "3");
        gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_closed");
        return;
    }
    if (g_form.getValue('assignment_group') == 'a7c1b92e1bab3110ad0a20a2b24bcb47') {
        if (g_user.userID != '46776fc81b5c4210ad0a20a2b24bcb35') {
            return false;
        }
    }
    g_form.setValue("state", "3");
    gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_closed");

}

if (typeof window == 'undefined')
    setRedirect();

function setRedirect() {
    current.update();
    action.setRedirectURL(current);
}

addLoadEvent(function() {
    if (g_user.hasRole('admin')) {
        return;
    }

    if (g_form.getValue('assignment_group') == 'a7c1b92e1bab3110ad0a20a2b24bcb47') {
        if (g_user.userID != '46776fc81b5c4210ad0a20a2b24bcb35') {
            var button = document.getElementById('state_model_move_to_closed');
            if (button) {
                button.disabled = true;
				button.style.backgroundColor = '#d3d3d3';
				button.style.color = '#666666';
				button.style.borderColor = '#b5b5b5';
                button.style.cursor = 'not-allowed';
            }
        }
    }
});

For request approval 1

function moveToAssess() {
    if (g_user.hasRole('admin')) {
        g_form.setValue("state", "-4");
        gsftSubmit(null, g_form.getFormElement(), 'state_model_request_assess_approval');
        return;
    }
    if (g_form.getValue('assignment_group') == 'a7c1b92e1bab3110ad0a20a2b24bcb47') {
        if (g_user.userID != '46776fc81b5c4210ad0a20a2b24bcb35') {
            return false;
        }
    }
	
    g_form.setValue("state", "-4");
    gsftSubmit(null, g_form.getFormElement(), 'state_model_request_assess_approval');
}

if (typeof window == 'undefined')
    updateAndRedirect();

function updateAndRedirect() {
    current.update();
    action.setRedirectURL(current);
}

addLoadEvent(function() {
    if (g_user.hasRole('admin')) {
        return;
    }

    if (g_form.getValue('assignment_group') == 'a7c1b92e1bab3110ad0a20a2b24bcb47') {
        if (g_user.userID != '46776fc81b5c4210ad0a20a2b24bcb35') {
            var button = document.getElementById('state_model_request_assess_approval');
            if (button) {
                button.disabled = true;
				button.style.backgroundColor = '#d3d3d3';
				button.style.color = '#666666';
				button.style.borderColor = '#b5b5b5';
                button.style.cursor = 'not-allowed';
            }
        }
    }
});

 

For request approval 2

function moveToAuthorize() {
    if (g_user.hasRole('admin')) {
        g_form.setValue("state", "-3");
        gsftSubmit(null, g_form.getFormElement(), 'state_model_request_cab_approval');
        return;
    }
    if (g_form.getValue('assignment_group') == 'a7c1b92e1bab3110ad0a20a2b24bcb47') {
        if (g_user.userID != '46776fc81b5c4210ad0a20a2b24bcb35') {    
            return false;
        }
    }
    g_form.setValue("state", "-3");
    gsftSubmit(null, g_form.getFormElement(), 'state_model_request_cab_approval');
}

if (typeof window == 'undefined')
    updateAndRedirect();

function updateAndRedirect() {
    current.update();
    action.setRedirectURL(current);
}

addLoadEvent(function() {
    if (g_user.hasRole('admin')) {
        return;
    }

    if (g_form.getValue('assignment_group') == 'a7c1b92e1bab3110ad0a20a2b24bcb47') {
        if (g_user.userID != '46776fc81b5c4210ad0a20a2b24bcb35') {
            var button = document.getElementById('state_model_request_cab_approval');
            if (button) {
                button.disabled = true;
				button.style.backgroundColor = '#d3d3d3';
				button.style.color = '#666666';
				button.style.borderColor = '#b5b5b5';
                button.style.cursor = 'not-allowed';
            }
        }
    }
});

 

Thanks a lot for your time 🙂 

-AK

1 REPLY 1

Ankur Bawiskar
Tera Patron

@AkshitG90438384 

so what's not working?

what debugging did you do?

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