service catalog

sravya Attluri
Tera Contributor

Hello,

 

Any on please help me on the below scenarios.

1)Employee name variable should contain only alphabets.

2)date of entry field must accept only current date (as per system date) and not past or future date.

 

Thanks in advance.

Sravya 

 

2 ACCEPTED SOLUTIONS

Anurag Tripathi
Mega Patron
Mega Patron

Here is how you can validate date through ui policy 

No Code date validations through (Catalog) UI Poli... - ServiceNow Community

 

 

For the check on name try this

Create onChange Client Script on that particular field.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var field = g_form.getValue('fieldname');
    if (!field.match(/^[A-Za-z ]*$/)) {
        alert('Please enter only text');
        g_form.clearValue('fieldname');
        return false;
    }
}

 

-Anurag

View solution in original post

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @sravya Attluri 

 

For the 2nd one, use Catalog UI Policy

LearnNGrowAtul_0-1706020078069.png

 

LearnNGrowAtul_1-1706020091274.png

 

For 1st one, you need to regex code. 

https://www.servicenow.com/community/developer-forum/how-to-validate-the-variable-with-validation-re...

 

 

*************************************************************************************************************
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]

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

View solution in original post

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Here is how you can validate date through ui policy 

No Code date validations through (Catalog) UI Poli... - ServiceNow Community

 

 

For the check on name try this

Create onChange Client Script on that particular field.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var field = g_form.getValue('fieldname');
    if (!field.match(/^[A-Za-z ]*$/)) {
        alert('Please enter only text');
        g_form.clearValue('fieldname');
        return false;
    }
}

 

-Anurag

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @sravya Attluri 

 

For the 2nd one, use Catalog UI Policy

LearnNGrowAtul_0-1706020078069.png

 

LearnNGrowAtul_1-1706020091274.png

 

For 1st one, you need to regex code. 

https://www.servicenow.com/community/developer-forum/how-to-validate-the-variable-with-validation-re...

 

 

*************************************************************************************************************
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]

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

Adrian Ubeda
Mega Sage
Mega Sage

Hello Sravya, 

In one hand, I will create a regex validation rule inside Service Catalog  > Variables > Validation Regex, and I'll add a new regex rule for checking if it's only characters on that name field, this regex can work: [a-zA-Z]. Check this link: https://www.servicenow.com/community/developer-articles/service-portal-catalog-items-regex-field-val...

In the second hand, I will use the default value inside default value tab and use something as follows: javascript: new GlideDateTime().getDate(). Also if you only want current date, past or future date it's now supposed to be allowed, then make it read only from dictionary definition.

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

Dr Atul G- LNG
Tera Patron
Tera Patron

LearnNGrowAtul_0-1706020925321.png

LearnNGrowAtul_1-1706020971580.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]

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