Client Script not working in Service Operations Workspace

Bret Smith
Giga Guru

want to not show certain states (remove state options)  depending on assignment group

 

This isnt working in Service Operations Workspace

BretSmith_1-1751386953723.png

 

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    var assignGrp = g_form.getDisplayBox('assignment_group').value;
    //alert(assignGrp);
    if (assignGrp.indexOf('Network Security Support') < 0) {
        g_form.removeOption('state', '10');
        g_form.removeOption('state', '11');
        g_form.removeOption('state', '12');
    } else if (assignGrp.indexOf('Network Security Support') >= 0) {
        // g_form.addOption('state', '10','Firewall Awaiting Customer');
        // g_form.addOption('state', '11','Firewall Rejection');
        // g_form.addOption('state', '12','Firewall Request CISO Approval');
        g_form.save();
    }
}
 
the onload script not working also 
function onLoad() {

    var assignGrp = g_form.getDisplayBox('assignment_group').value;
    //alert(assignGrp);
    if (assignGrp.indexOf('Network Security Support') < 0) {
        g_form.removeOption('state', '10');
        g_form.removeOption('state', '11');
        g_form.removeOption('state', '12');
    }
}
 
BretSmith_0-1751386936190.png

 

 
1 ACCEPTED SOLUTION

Bret Smith
Giga Guru

This is the solution from my colleague:
Client Script and instead of using g_form.getDisplayBox, change to use g_form.getDisplayValue
Important note: 

    var assignGrp = g_form.getDisplayValue('assignment_group'); //Needed for SOW to work
    var assignGrpSysID = g_form.getValue('assignment_group'); //Needed for backend(UI 16) to work

Here is the client script we have implemented
function onChange(control, oldValue, newValue, isLoading) {
    // if (isLoading || newValue === '') {
    //     return;
    // }

    var assignGrp = g_form.getDisplayValue('assignment_group'); //Needed for SOW to work
    var assignGrpSysID = g_form.getValue('assignment_group'); //Needed for backend(UI 16) to work
    //alert(assignGrpSysID + ' ' + assignGrp);
    if (assignGrp == 'Network Security Support' || assignGrpSysID == 'd73c10441ba7d95468314000f54bcb7d' || assignGrp == 'Firewall Security Architecture Review' || assignGrpSysID == 'abb340071be3f51055cfa791604bcb6f') {
        g_form.addOption('state', '10', 'FSR Awaiting Customer', '3');
        g_form.addOption('state', '11', 'FSR Canceled', '4');
        g_form.addOption('state', '12', 'FSR Requires Security Architecture Review', '5');
    } else {
        g_form.removeOption('state', '10');
        g_form.removeOption('state', '11');
        g_form.removeOption('state', '12');
    }
}


 


 

View solution in original post

3 REPLIES 3

Chaitanya ILCR
Kilo Patron

Hi @Bret Smith ,

should be because of getDisplayBox method

 

instead to this

 

create a client callable script include

ChaitanyaILCR_0-1751387329823.png

 

var GetAssignmentGroupDisplayValue = Class.create();
GetAssignmentGroupDisplayValue.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getGroupDisplayValue: function() {
        var groupSysId = this.getParameter('sysparm_group_sys_id');
        var groupGR = new GlideRecord('sys_user_group');
        if (groupGR.get(groupSysId)) {
            return groupGR.getDisplayValue();
        }
        return '';
    },

    type: 'GetAssignmentGroupDisplayValue'
});

 

update onload client script as 

function onLoad() {
    var groupSysId = g_form.getValue('assignment_group');

    var ga = new GlideAjax('GetAssignmentGroupDisplayValue');
    ga.addParam('sysparm_name', 'getGroupDisplayValue');
    ga.addParam('sysparm_group_sys_id', groupSysId);
    ga.getXMLAnswer(function(response) {
        var assignGrpDisplayValue = response;

        if (assignGrpDisplayValue.indexOf('Network Security Support') < 0) {
            g_form.removeOption('state', '10');
            g_form.removeOption('state', '11');
            g_form.removeOption('state', '12');
        }
    });
}

 

onchange client script as

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var groupSysId = g_form.getValue('assignment_group');

    var ga = new GlideAjax('GetAssignmentGroupDisplayValue');
    ga.addParam('sysparm_name', 'getGroupDisplayValue');
    ga.addParam('sysparm_group_sys_id', groupSysId);
    ga.getXMLAnswer(function(response) {
        var assignGrpDisplayValue = response;

        if (assignGrpDisplayValue.indexOf('Network Security Support') < 0) {
            g_form.removeOption('state', '10');
            g_form.removeOption('state', '11');
            g_form.removeOption('state', '12');
        } else {
            // Uncomment if you want to add options dynamically
            // g_form.addOption('state', '10','Firewall Awaiting Customer');
            // g_form.addOption('state', '11','Firewall Rejection');
            // g_form.addOption('state', '12','Firewall Request CISO Approval');
            g_form.save(); // Only use if you want to auto-save the form
        }
    });
}

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

Bret Smith
Giga Guru

This is the solution from my colleague:
Client Script and instead of using g_form.getDisplayBox, change to use g_form.getDisplayValue
Important note: 

    var assignGrp = g_form.getDisplayValue('assignment_group'); //Needed for SOW to work
    var assignGrpSysID = g_form.getValue('assignment_group'); //Needed for backend(UI 16) to work

Here is the client script we have implemented
function onChange(control, oldValue, newValue, isLoading) {
    // if (isLoading || newValue === '') {
    //     return;
    // }

    var assignGrp = g_form.getDisplayValue('assignment_group'); //Needed for SOW to work
    var assignGrpSysID = g_form.getValue('assignment_group'); //Needed for backend(UI 16) to work
    //alert(assignGrpSysID + ' ' + assignGrp);
    if (assignGrp == 'Network Security Support' || assignGrpSysID == 'd73c10441ba7d95468314000f54bcb7d' || assignGrp == 'Firewall Security Architecture Review' || assignGrpSysID == 'abb340071be3f51055cfa791604bcb6f') {
        g_form.addOption('state', '10', 'FSR Awaiting Customer', '3');
        g_form.addOption('state', '11', 'FSR Canceled', '4');
        g_form.addOption('state', '12', 'FSR Requires Security Architecture Review', '5');
    } else {
        g_form.removeOption('state', '10');
        g_form.removeOption('state', '11');
        g_form.removeOption('state', '12');
    }
}


 


 

Client Script 
onChange when Assignment group changes

SOW uses the group name

var assignGrp = g_form.getDisplayValue('assignment_group'); //Needed for SOW to work


the backend (UI 16) uses the sys_id of the group name

var assignGrpSysID = g_form.getValue('assignment_group'); //Needed for backend(UI 16) to work

 

BretSmith_0-1753370337274.png