Catalog Item - No Time Only Variable

Matt20
Tera Expert

I'm working on creating a new Catalog Item for requesting a scheduled report.  As part of this I need a way for the requester to enter what time of day they want the report to run, but there is not a variable for Time only.  There is Date and Date/Time.  I did some digging and it looks like people are using Select Box variables and populating them with options for every 30 minutes throughout the day, but I'm looking for someone that allows them to enter a specific time down to the minute.

Does anyone have some suggestions on how I can get this done?

1 ACCEPTED SOLUTION

Brian Lancaster
Tera Sage

You could single line text field with some examples of the format.  Then use a regular expression to validate what they have entered.  Example regular expression below for 24 hour clock.  

24 Hour clock

/^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/

12 Hour clock

/((1[0-2]|0?[1-9]):([0-5][0-9]) ?([AaPp][Mm]))/

View solution in original post

8 REPLIES 8

vams1
Tera Contributor

Hello Brian,

 

can you please explain little more or how to achive this functanality.

You would use an on change client scrip with a regular expression.  If it does not meeting the regular expression then you toss up an alert and wipe the field?

Can you provide the script that would do this?

 

Thanks,

Brandon

The code would look like this in an onChange client script.  Typically when I have these my variable is mandatory so I just clear the value they put and popup an alert.

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

    //Type appropriate comment here, and begin script below
    var pattern = /^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/.test(newValue);
    if (!pattern) {
        g_form.setValue('employee_id', '');
        alert("Time must be in 24 hour clock format.");
    }

}