Checking incident opened date vs closed date

gu2
Kilo Explorer

hi All.

I am quite new on service now

I am trying to write a script that checks if an incident closed is after the opened date.

I manage to get the closed date with g_form.getValue('closed_at'). but g_form.getValue('opened_at') return an empty value.

Help...

6 REPLIES 6

DilipKumar DJ
Kilo Guru

Hi Gilles,



g_form only works on client side and field should be available on form for fetching value. Logically closed data will be after opened date. May I know what exactly is your requirement and which script you have been trying


Hi Dilip, the script I am trying to make is something like this :


function onSubmit() {



    if(g_form.getValue('closed_at') > g_form.getValue('opened_at')){


            return false;


//and some other fancy stuff here.


    }


}


You are right the opened date is not on the form. How can i get it?


My requirement is to avoid to closed an incident (intentionnaly or not) with a date before the opened date.


Steven G_
Tera Expert

Hi Gilles,



There should be an OOB field for opened_at and closed_at. These should be populated automatically by the platform. You can then use the date time stamps and write logic against it. What is the use case for what you are looking to do?


hi Steven,


Sorry for my questions, whats is   OOB. I have to write a script that avoid closed date typing mistake, when closing an incident.


I began with this   :


function onSubmit() {


    if(g_form.getValue('closed_at') > g_form.getValue('opened_at')){


            return false;


    }


}


not working.



thanks in advance.