Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

I do not want the ability for user to select any groups which are in the IT tenancy.

akashgujar
Tera Contributor

.

I want to restrict user to use Groups in catalog Item where Assignment Group Contains IST and tenancy is 'IT'

2 REPLIES 2

Not applicable

Hi @akashgujar ,

 try this on change client script and do necessary changes.

function onChange(control, oldValue, newValue, isLoading) {
    // Ensure the form is not loading
    if (isLoading) return;

    // Get the value of the Assignment Group field and the Tenancy field
    var assignmentGroup = g_form.getValue('assignment_group');
    var tenancy = g_form.getValue('tenancy'); // Assuming you have a tenancy field

    // Check if the Assignment Group contains 'IST' and the tenancy is 'IT'
    if (assignmentGroup.indexOf('IST') !== -1 && tenancy == 'IT') {
        // If the condition is met, display an error and reset the field
        g_form.showFieldMsg('assignment_group', 'Selection of this group is restricted for IT tenancy', 'error');
        
        // Optionally, you can clear the value of the Assignment Group field
        g_form.setValue('assignment_group', '');
    }
}

Shruti D
Kilo Sage

Hello @akashgujar 

Try with the below Script:

// Client Script: onLoad or onChange Script
function onLoad() {
  var userTenancy = g_user.tenancy; // Get the user's tenancy
  
  // Check if Tenancy is 'IT'
  if (userTenancy === 'IT') {
    var assignmentGroupField = g_form.getControl('assignment_group'); 

    // GlideRecord to query for assignment groups containing 'IST'
    var gr = new GlideRecord('sys_user_group');
    gr.addQuery('name', 'CONTAINS', 'IST'); // Look for groups containing 'IST'
    gr.query();

    var groupNames = [];
    while (gr.next()) {
      groupNames.push(gr.name.toString()); // Collect the group names in an array
    }


    if (groupNames.length > 0) {
      var assignmentGroupValue = g_form.getValue('assignment_group'); // Get the selected group value


      if (groupNames.includes(assignmentGroupValue)) {
        g_form.setDisplay('assignment_group', false);  // Hide the Assignment Group field
        g_form.setValue('assignment_group', ''); // Clear the field value
      }
    }
  }
}

 

Please Mark Correct  ✔️ if this solves your query and also mark Helpful  👍 if you find my response worthy based on the impact.

Regards,
Shruti