The CreatorCon Call for Content is officially open! Get started here.

On change of requested for need to check a group member if part of group show other variable choice

vinnus
Tera Contributor

On change of requested for variable(user reference) check if user part of a group if yes show one of the choice of other variable else remove the option.

i have working catalog client script and Script include its is working for on change, i need to work on load as well, we are setting requested for default to current logged in user, my script is working on only on change after page loads need to work on load as well with my script, please help me out. THANKS 

 

CIENT SCRIPT:

function onChange(control, oldValue, newValue, isLoading) {
    if ( newValue == '') {
        return;
    }
    var ga = new GlideAjax('x_jj_dfit.DFITUtilsAjax');
    ga.addParam('sysparm_name', 'isMemberOfMockclose');
    ga.addParam('sysparm_user', newValue);
    //ga.addParam('sysparm_user', oldValue);
    ga.getXMLAnswer(processResponse);

    function processResponse(response) {
   //var Usr = g_form.getValue('requested_for_dti');
   
if (response == 'true') {
    g_form.addOption('planning_version', 'SIM-ACT', 'Mock Close (Actuals)');
    } else {  
     g_form.removeOption('planning_version', 'SIM-ACT','Mock Close (Actuals)');
   
    }
    }
  }
 
SCRIPT INCLUDE:
isMemberOfMockclose: function() {
        // check if user is a member of the group
        var group = gs.getProperty('x_jj_dfit.SMF.Mock.Close.Non-agents');
        var user = this.getParameter("sysparm_user");
        //var group = this.getParameter("sysparm_grp");
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', user);
        gr.addQuery('group', group);
        gr.query();
        if (gr.next()) {
            return true;
        } else {
            return false;
        }
4 REPLIES 4

Mark Manders
Mega Patron

You are only sharing your onChange script. What happens when you use the same script onLoad?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Not working!!

'not working' doesn't help us in helping you. What did you do? What was the result?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

T_Prashaanth
Mega Guru

Hi @vinnus the script seems to be looking correct, as you have removed the isLoading check in the initial if loop script,can you verify if the logged in user is setting/populating correctly . If that should work , then I see the logic should be working correctly onLoad as well .

 

Please , mark my answer as correct/helpful if its useful