Dismiss Notice
We would like to remind you that we’re updating our login process for all 3CX forums whereby you will be able to login with the same credentials you use for the Partner or Customer Portal. Click here to read more.

Get current datetime for use in VAD?

Discussion in 'CRM / Helpdesk / App Integration' started by millsey, Apr 14, 2013.

Thread Status:
Not open for further replies.
  1. millsey

    millsey New Member

    Joined:
    Dec 21, 2011
    Messages:
    203
    Likes Received:
    0
    I need to get the current date and time as seen by the server for inclusion as a field in a SQL query.

    I have tried

    DATE()

    as a javascript expression but it does not work and there is a line in the log file:
    21:36:10.562|10832|(0):Error! Module '3CX.com.OSBjsi'. Error ID 501. errmsgReferenceError: DATE is not definedline1linetxttokentxt

    I need to get this working, Ideally I would like to supply this date in a way SQL server can accept directly.

    Millsey
     
  2. VAD_Support

    VAD_Support Active Member

    Joined:
    Aug 6, 2009
    Messages:
    690
    Likes Received:
    0
    Maybe it's better to get the current date and time into the SQL statement. The syntax depends on the server, for example for SQL Server you can use "GETDATE()", or for PostgreSQL you can use "now()".

    Regards,
     
  3. millsey

    millsey New Member

    Joined:
    Dec 21, 2011
    Messages:
    203
    Likes Received:
    0
    I actually need to find a way to get this working. Pulling the date and time from 3CX is important since it gives us a change to accurately match calls hitting the VAD with other data we use from the postgresql database.

    I am already logging the datetime the SQL stored procedure is run but there are discrepancies between 3cx timing and the time the stored procedure is run.

    What expression or command can I use to get the date and time into a string which I can include as a parameter int eh SQL statement?
     
  4. VAD_Support

    VAD_Support Active Member

    Joined:
    Aug 6, 2009
    Messages:
    690
    Likes Received:
    0
    Hi Millsey,

    The following article explains how to set the current hour to a variable, using a javascript expression:
    http://www.3cx.com/blog/voip-howto/javascript-3cx-vad/

    You just need to work with the javascript expression. For example, "new Date()" returns a javascript date time object containing the current date time of the 3CX server. Here you have the reference of the Date object:
    http://www.w3schools.com/jsref/jsref_obj_date.asp

    There are different methods to convert it to a string, with different formats. For example, you could use the method "toDateString()" or "toISOString()", or any other method to convert the Date to string. That way, your expression will be for example:
    new Date().toDateString()

    Then you can pass the string variable as a parameter to your SQL query.

    Hope the information helps.
     
Thread Status:
Not open for further replies.