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
Tera Patron

Hi @Sowmya 

 

did you try with UI policy

Like 

contains

these words. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

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/atul_grover_lng [ Connect for 1-1 Session]

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

Aniket Chavan
Tera Sage
Tera Sage

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

Amit Verma
Kilo Patron
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


Please mark this response as correct and helpful if it assisted you with your question.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Sowmya 

 

LearnNGrowAtul_0-1706785193483.png

 

LearnNGrowAtul_1-1706785203367.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

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/atul_grover_lng [ Connect for 1-1 Session]

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