help using Javascript exrpessions

Status
Not open for further replies.

Michaelhal

Joined
Nov 18, 2011
Messages
8
Reaction score
0
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 https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date.

But none of them seem to work

can anyone help me out using the correct expressions ?

Thanks in advance
 
Hi,

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.
 
Status
Not open for further replies.

Forum statistics

Threads
112,320
Messages
591,873
Members
165,466
Latest member
EMMEPICASA