Sorting Users based on MRVS Variable

Walter Toney
Tera Expert

Team,

 

Thanks for all the past help im learning a lot.

 

i have a requirement to only show only contractors for the sys_user table if a MRVS Variable is set.

Sys_user table has a variable for Employee or Contractor

 

Field on User Table

Employment status : Full Time and Contractors

 

 

we built a SC_request and there is a MRVS , we will be pulling names of User from the  sys_user table and they want us to sort the users based on another variable in the MRVS called Role_type that is a Select box. 

 

 

so what i need help with is .... 

If the Selection of Role Type  - (PPOC), and (APOC) we only want to see Fulltime user

and if the Role Type is (TPOC) - we want to show all Fulltime and Contractors

 

 

Im looking for the best way to make this happen

 

 

 

 

 

1 ACCEPTED SOLUTION

SwarnadeepNandy
Mega Sage

Hello @Walter Toney,

To filter the sys_user table based on a MRVS variable, you can use the following steps:

  • Create a catalog client script for the MRVS variable that will run onChange of the Role Type field. This script will get the value of the Role Type field and set the filter condition for the User field accordingly. For example, you can use something like this:

 

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

  //Get the MRVS variable name and sys_id
  var mrvsName = 'mrvs_variable';
  var mrvsId = g_form.getControl(mrvsName).id;

  //Get the current row index
  var rowIndex = g_form.getControl(control.name).getAttribute('row_index');

  //Get the User field name and element
  var userField = mrvsName + '.' + rowIndex + '.user';
  var userElement = g_form.getControl(userField);

  //Set the filter condition based on the Role Type value
  var filter = '';
  if (newValue == 'PPOC' || newValue == 'APOC') {
    filter = 'employment_status=Full Time';
  } else if (newValue == 'TPOC') {
    filter = 'employment_status=Full Time^ORemployment_status=Contractor';
  }

  //Apply the filter to the User field
  userElement.setAttribute('slushbucket_ref_ac_columns', 'name');
  userElement.setAttribute('slushbucket_ref_ac_order_by', 'name');
  userElement.setAttribute('ref_qual', filter);
}​

 

 

  • Save and test the catalog client script. You should see that the User field will only show the users that match the filter condition based on the Role Type value.

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy

View solution in original post

1 REPLY 1

SwarnadeepNandy
Mega Sage

Hello @Walter Toney,

To filter the sys_user table based on a MRVS variable, you can use the following steps:

  • Create a catalog client script for the MRVS variable that will run onChange of the Role Type field. This script will get the value of the Role Type field and set the filter condition for the User field accordingly. For example, you can use something like this:

 

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

  //Get the MRVS variable name and sys_id
  var mrvsName = 'mrvs_variable';
  var mrvsId = g_form.getControl(mrvsName).id;

  //Get the current row index
  var rowIndex = g_form.getControl(control.name).getAttribute('row_index');

  //Get the User field name and element
  var userField = mrvsName + '.' + rowIndex + '.user';
  var userElement = g_form.getControl(userField);

  //Set the filter condition based on the Role Type value
  var filter = '';
  if (newValue == 'PPOC' || newValue == 'APOC') {
    filter = 'employment_status=Full Time';
  } else if (newValue == 'TPOC') {
    filter = 'employment_status=Full Time^ORemployment_status=Contractor';
  }

  //Apply the filter to the User field
  userElement.setAttribute('slushbucket_ref_ac_columns', 'name');
  userElement.setAttribute('slushbucket_ref_ac_order_by', 'name');
  userElement.setAttribute('ref_qual', filter);
}​

 

 

  • Save and test the catalog client script. You should see that the User field will only show the users that match the filter condition based on the Role Type value.

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy