Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Duration type variable on the Service Catalog to accept only numeric values

Revathi10
Tera Expert

I have made the Duration type variable Mandatory. There are two issues here:

1. On the Service Portal view, the Duration type field is accepting '0' number and becoming non-mandatory.

Before :

find_real_file.png

After:

find_real_file.png

2. Duration type field is accepting alphabets while placing order

find_real_file.png

 

I have tried onChange client scripts for point 2, but nothing is working.

1 ACCEPTED SOLUTION

The Time duration field returns 00 00:00:00 even when we don't give any value. I have written the below OnSubmit client script  and it works.

 

function onSubmit() {
    //Type appropriate comment here, and begin script below

    var value = g_form.getValue("time_duration");
    var day = value.split(" ");
    var time = day[1].split(":");
    var counter = 0;

    if (day[0] > 0)
        return true;
    else {
        for (var i = 0; i < 3; i++) {
            if (time[i] > 0)
                return true;
            else
                counter++;
        }
    }
    
    if (counter > 0) {
        alert("Enter the right Time Duration value!");
        g_form.clearValue("time_duration");
        return false;
    }
    
}

View solution in original post

3 REPLIES 3

Aman Kumar S
Kilo Patron

Hi @Revathi ,

If mandatory doesn't work, you can try using onSubmit client script here, your condition could be something as:

if(g_form.getValue("time_duration_backend_name") == ''){

     g_form.showFieldMsg("time_duration_backend_name", "No duration value filled!", "error");
}

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

Best Regards
Aman Kumar

The Time duration field returns 00 00:00:00 even when we don't give any value. I have written the below OnSubmit client script  and it works.

 

function onSubmit() {
    //Type appropriate comment here, and begin script below

    var value = g_form.getValue("time_duration");
    var day = value.split(" ");
    var time = day[1].split(":");
    var counter = 0;

    if (day[0] > 0)
        return true;
    else {
        for (var i = 0; i < 3; i++) {
            if (time[i] > 0)
                return true;
            else
                counter++;
        }
    }
    
    if (counter > 0) {
        alert("Enter the right Time Duration value!");
        g_form.clearValue("time_duration");
        return false;
    }
    
}

hi @Revathi10 , @Aman Kumar S 
When the user is submitting the catalog by giving data, hours  value in the Duration variable, it showing some wired numeric value.
Can you help me to fix it?