Restrict user to give only Time format in string field

Kruthik M Shiva
Tera Contributor

Hi,
I have a requirement to allow users to give only this format in the string field, since time type is not supported in portal I am going with string type, so I want that particular field to take only this format 10:00 AM /PM. How to do this if anyone has pointers and code for this, please do share.
Thanks,
Kruthik Shivaprasad

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Kruthik M Shiva 

 

If this is the case , better to change the data type instead of puting validation, that will increase tech debt and can be problem at time of reporting as well. 

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

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

Hi AG,
The client ask is to give the string field and want this validation, so we cannot change type also in portal for form the time type is not supported this is the ServiceNow limitation.
Thanks

Hi @Kruthik M Shiva 

 

What do mean by not supported on portal, we can create date type variable on portal. OOTB we have Date/Time as data type and better to use that which make life easy mate.

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

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

Harish_K07
Giga Guru

Hi @Kruthik M Shiva,

 

I understand your concern because we do not have a type of variable specific to only 'Time' but Date/Time. 

 

At the same time, @Dr Atul G- LNG is right about increase in tech debt if we customize this variable with an onChange script. The only ways I see this working would be to

 

  • Use a string type of variable and force the user to enter in the time (with a help text or tooltip).
  • Use a dropdown with choices of allowable time's like maybe 24 options one for each hour.

Mark as correct and helpful if it solved your query.

Regards,

Harish