help using Javascript exrpessions

Discussion in 'CRM / Helpdesk / App Integration' started by Michaelhal, Nov 18, 2011.

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

    Nov 18, 2011
    Likes Received:
    Dear 3cx support team,

    I have some problems using the VAD javascript expressions.
    in the record component i am trying to save files using a java time +date expression currently i am using new Date().getHours() and it returns me the hour format like 17. ( i found this expression on your website under "using javascript expressions in VAD'

    currently i am using this expression:
    CONCATENATE('audioofclients\\',new date().getHours,'.wav')

    It saves file`s in a specific folder and names it 17.wav

    But i want to save files with the day,month,year hours and minute`s format so it wil look like 18-11-2011 17.16.wav

    so i tryed new Date().getHours().getMinutes() but this expression didnt work properly( not at all) i tried many different expressions from this site

    But none of them seem to work

    can anyone help me out using the correct expressions ?

    Thanks in advance
  2. VAD_Support

    VAD_Support Active Member

    Aug 6, 2009
    Likes Received:

    A first approach could be using the following expression:
    CONCATENATE('audioofclients\\', new date().getFullYear(), '-', new date().getMonth() + 1, '-', new date().getDate(), ' ', new date().getHours(), '.', new date().getMinutes(), '.wav')

    But there if the date/time changes between 2 calls to new date() you will be generating an invalid value. So, my suggestion is creating a javascript function that returns that. For example, something like this:

    function getCurrentDateTimeAudioFileName()
    var currentDt = new date();
    return 'audioofclients\\' + currentDt.getFullYear() + '-' + (currentDt.getMonth() + 1) + '-' + currentDt.getDate() + ' ' + currentDt.getHours() + '.' + currentDt.getMinutes() + '.wav';

    Then put that code into a .js file and use it into an ExternalCodeExecution component. Then, from the record component create an expression to get the result from that ExternalCodeExecution component.

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