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 thanks for your solution. 

Using the above mentioned onload client script am able to set the cloud type value for Infra-Cloud-Azure BA & Infra - Cloud BA as "CSP" and its in read only state in form view.

GautamRaj_0-1738131512768.pngGautamRaj_1-1738131555614.png

but for other Business applications according to the onload client script the CSP option should be removed right from the form view ? but if i check for few samples am able to see the "CSP" cloud type option in the dropdown which shouldn't be coming. Can you advise on this?

GautamRaj_2-1738131846161.png

 

@Gautam Raj 

If it worked for setting and making readonly then it should work for other case as well

did you give the correct choice value?

Also is the name field present on form or not?

As per screenshot I could not see

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 yes i have given the correct choice value 

GautamRaj_0-1738132484159.png

GautamRaj_1-1738132553120.png

GautamRaj_3-1738132774268.png

 

 

Name field is present in the form too please find the below screenshot

GautamRaj_2-1738132721569.png

 

 

 

@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

@Gautam Raj  - Try by putting alert statement in onload client script given by Ankur in else part and try to debug why it is not working.