Restriction of Choices list

Gautam Raj
Tera Contributor

Can we restrict a choice list to a specific entry alone? 

Am having a business application with cloud type as IaaS. I need to add an additional choice (CSP) under the choices tab in dictionary entry and restrict it to only one business application. Is that possible.

 

For example in the below BA could type should be marked as CSP and that choice should only be restricted to this BA. is that possible ?

GautamRaj_0-1738056520807.png

 

2 ACCEPTED SOLUTIONS

@Gautam Raj 

then do this

1) use list_edit ACL and block the edit operation

2) Now for form level do this (client script on table cmdb_ci_business_app)

a) create onLoad client script and check if the name is Infra-Cloud-Azure BA or Infra - Cloud BA, if yes then set the choice value and make readonly

b) in same onLoad if value is not that then remove that option from choice

function onLoad() {
    var name = g_form.getValue('name');
    if (name == 'Infra-Cloud-Azure BA' || name == 'Infra - Cloud BA') {
        g_form.setValue('u_cloud_type', 'CSP')
        g_form.setReadOnly('u_cloud_type', true);
    } else {
        g_form.removeOption('u_cloud_type', 'CSP');
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

@Gautam Raj 

the value in choice is csp and not CSP

so you need to give csp when you use removeOption

here is the updated code

function onLoad() {
    var name = g_form.getValue('name');
    if (name == 'Infra-Cloud-Azure BA' || name == 'Infra - Cloud BA') {
        g_form.setValue('u_cloud_type', 'csp')
        g_form.setReadOnly('u_cloud_type', true);
    } else {
        g_form.removeOption('u_cloud_type', 'csp');
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

21 REPLIES 21

Ankur Bawiskar
Tera Patron
Tera Patron

@Gautam Raj 

on form you can handle it using onLoad client script

for list you can use list edit client script and stop user from selecting the choice

what did you try so far and what didn't work?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar I Haven't tried anything i need idea to get this done

@Gautam Raj 

something like this

Example: incident cannot be set as Closed, Resolved or On Hold from list

You can enhance as per your requirement

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {

  var saveAndClose = true;
  if(newValue == '6' || newValue == '7' || newValue == '9'){
  alert('Not allowed');
  saveAndClose = false;
  } else {
  saveAndClose = true;
  }
callback(saveAndClose);

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar Thanks for the example. In my case i have to add a choice list named "CSP" under cloud type and it should be restricted only to a specific BA "Infra-Cloud-Azure BA" . We should not be able to use the CSP cloud type choice for any other BA. Cloud type "CSP"  should be hidden from the drop down for other BA's

GautamRaj_0-1738060103739.png