How to display choices for a field based upon if the current user is part of an assignment group in List view ?

Sarin
Tera Contributor

Trying to display choices for a particular field in List view if the current user is part of a specific assignment group. Created choices for the field through Dictionary entry and tried using a query BR to check of the user is part of the assignment group or not and then set the choices as inactive, however not able to update the fields. Any pointers will be helpful.

Script:

  var rec = new GlideRecord('sys_choice');
  var queryString = 'element=state^name=sc_task';
  rec.addEncodedQuery(queryString);
  rec.query();
    while (rec.next()) {
        if (gs.getUser().isMemberOf('Help Desk')) {
            rec.inactive = false;
        } else {
            rec.inactive = true;
        }

rec.update;   
    }

5 REPLIES 5

Vamsi Sreenivas
Giga Guru

Hi Sarin, did you try using onCellEdit client script where you can use script to remove options/choice and display choices you need.

Link to docs: search for onCellEdit

https://docs.servicenow.com/bundle/paris-application-development/page/script/client-scripts/concept/...

 

Regards,

Vamsi S

Hi @Vamsi Sreenivas,

Had tried, it didn't work. 

Thanks much!

can you share the OnCellEdit script that you tried?

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
    var saveAndClose = true;

    if (g_scratchpad.memberOfGrp == true) {

        g_form.removeOption('state', 'Cancel');
        g_form.addOption('state', 'Acknowledged', 'Acknowledged');
        g_form.addOption('state', 'In Progress', 'In Progress');
        

    } else {

        g_form.removeOption('state', 'Acknowledged', 'Acknowledged');
        g_form.removeOption('state', 'In Progress', 'In Progress');
        g_form.addOption('state', 'Cancel', 'Cancel');
    }

    callback(saveAndClose);
}