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

@Gautam Raj 

what's your requirement? you want to set it or restrict it?

the script you are using is wrong and has setChoice() method which is not available

try this if you wish to set the choice value, ensure you give correct sysId to compare and correct choice value

you should use g_form.setValue()

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    var baSysId = g_form.getValue('name');
    var restrictedBA = '44b1c5f6875d1158aa2fa6890cbb35c1';

    if (baSysId == restrictedBA) {
        g_form.setValue('u_cloud_type', 'CSP')
        g_form.setReadOnly('u_cloud_type', true);
    } else {
        g_form.setReadOnly('u_cloud_type', false);
    }
}

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

Hi @Ankur Bawiskar requirement is as below : 

i want to set the cloud type as CSP for the below mentioned BA's alone and should be read only.

Infra-Cloud-Azure BA

Infra - Cloud BA

 

and restrict the CSP option and allow all others from the cloud type field for all the other BA's.

 

 

 

 

@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

@Gautam Raj 

Hope you are doing good.

Did my reply answer your question?

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

@Gautam Raj 

Thank you for marking my response as helpful.

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