Time variable on Catalog request form

Madhu27
Tera Expert

Hi,

I would like to ask the user to to enter work schedule time from Monday - Saturday on catalog form. I need time variable like   00:00 am/pm. But I could not find it in the variable list. I see Date and Date/Time variables only. Could you please suggest in any other way we can do this?

Thanks

17 REPLIES 17

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Madhusudana,



Have a variable of type ui page and add below code. It will show duration field.



HTML


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">



<html>


<table>


<th>Hours</th>


<th>Minutes</th>


<!-- <th>Seconds</th> -->


<tr>


<td><input type="number" min="0" max="23" id="hours" onChange="validateHours(this.value)"/></td>


<td><input type="number" min="0" max="59" id="minutes" onChange="validateMinutes(this.value)"/></td>


<!-- <td><input type="number" min="0" max="59" id="seconds" onChange="validateSeconds(this.value)"/></td> -->


</tr>


</table>


</html>


</j:jelly>



Client Script: To validate hours are from 0-23 and minutes are from 0-60



function validateHours(value){


  if(value<0 || value>23){


  alert("Value should be in range 0-23");


  document.getElementById("hours").value = 0;


  }


}



function validateMinutes(value){


  if(value<0 || value>59){


  alert("Value should be in range 0-60");


  document.getElementById("minutes").value = 0;


  }


}



function validateSeconds(value){


  if(value<0 || value>59){


  alert("Value should be in range 0-60");


  document.getElementById("seconds").value = 0;


  }


}




Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, I found this script from your previous post which is very helpful. I don't need seconds and need AM/PM drop down. and also table width for one cell (eg. for hours) need to be reduced to half to fit on page correctly. could you please help me to change the above script?


Ok Sure,



I will update that script and add it here.



Regards


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Madhusudana,



Here is the updated script with AM/PM drop down. you can check further using table width on your own for look and feel as per html



<table>


  <th>Hours</th>


  <th>Minutes</th>


  <th>AM/PM</th>


  <tr>


  <td><input type="number" min="0" max="23" id="hours" onChange="validateHours(this.value)"/></td>


  <td><input type="number" min="0" max="59" id="minutes" onChange="validateMinutes(this.value)"/></td>


  <td><select name="duration" id="duration">


  <option value="am">AM</option>


  <option value="pm">PM</option>


  </select></td>


  </tr>


  </table>



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader