We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to restrict user to enter only specific vales in Service Catalog

Sowmya
Tera Contributor

How to restrict a user to enter only specific values like "(“/”, “/usr”, “/home”, “/boot”, “/boot/efi”, “/dev”, “/tmp”, “/var”, “/opt) in  a single line text in a Catalog?

 

 

4 REPLIES 4

Dr Atul G- LNG
Tera Patron

Hi @Sowmya 

 

did you try with UI policy

Like 

contains

these words. 

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

AniketC85155510
Kilo Patron

Hello @Sowmya ,

Please try the below code in catalog client script and see how it works for you , I have tested it from my end and its working fine for me so just let me know your views on this.

onChange Client Script:

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

    var forbiddenValues = ["/", "/usr", "/home", "/boot", "/boot/efi", "/dev", "/tmp", "/var", "/opt"];
    
    for (var i = 0; i < forbiddenValues.length; i++) {
        if (newValue.includes(forbiddenValues[i])) {
            var errorMessage = "Invalid value. The entered value is not allowed.";
            alert(errorMessage);
            g_form.setValue('description', '');  // Clear the 'description' field if an invalid value is entered
            return;
        }
    }
}

AniketChavan_0-1706783673183.png

 

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

 

Thanks,

Aniket

vermaamit16
Kilo Patron

Hi @Sowmya

 

The simplest way to do this is to make use of the  Validation Regex functionality. Define a regular expression for a variable by referring this link https://docs.servicenow.com/bundle/tokyo-servicenow-platform/page/product/service-catalog-management... and with regular expression ^(\/[^/ ]*)+\/?$

 

AmitVerma_0-1706783856937.png

 

Then configure the Validation Regex for your Single Line Text as below :

 

AmitVerma_1-1706783906129.png

 

Output :

 

AmitVerma_2-1706783940488.png

 

Thanks & Regards

Amit Verma

Thanks and Regards
Amit Verma

Dr Atul G- LNG
Tera Patron

Hi @Sowmya 

 

LearnNGrowAtul_0-1706785193483.png

 

LearnNGrowAtul_1-1706785203367.png

 

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************