---
title: "JavaScript"
canonical: "https://docs.getxray.app/space/XRAYCLOUD/44566578/JavaScript"
format: markdown
---
<span style="color: #333333">The Xray </span>[<span style="color: #333333">Document Generator</span>](https://getxraydocs.atlassian.net/wiki/spaces/XRAYCLOUD/pages/44565169)<span style="color: #333333"> allows rendering Tests based </span><span style="color: #333333">on</span><span style="color: #333333"> JavaScript. The notation is: </span>`%{<Javascript>}`

## Examples

<details>
<summary>Output the current date</summary>

```
%{( new Date()).getDate() +  "/" + (( new Date()).getMonth()+ 1 ) +  "/" + ( new Date()).getFullYear()}
```
</details>

<details>
<summary>Format the Creation Date in the dd-MM-yyyy HH:mm format (01-03-1978 8:00)</summary>

```
%{var dateTime = '${dateformat("dd-MM-yyyy HH:mm:ss"):Created}'.split( ' ' ); var date = dateTime[ 0 ]; var time = dateTime[ 1 ]; var dateParts = date.split( '-' );
 var timeParts = time.split( ':' ); dateParts[ 2 ] +  '-' + dateParts[ 1 ] +  '-' + dateParts[ 0 ] +  ' ' + timeParts[ 0 ] +  ':' + timeParts[ 1 ]} 
```
</details>

<details>
<summary>Format the Creation Date in the dd-MM-yyyy format (03-01-1978)</summary>

```
%{'${dateformat("dd-MM-yyyy HH:mm:ss"):Created}'.substring( 0 , 10 )}
```
</details>

<details>
<summary>Format the Creation Date in the MMM d yyyy format (Jan 3, 1978)</summary>

```
%{var months = new Array( 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' );var dateParts = '${dateformat(“d-MM-yyyy HH:mm:ss”):Created}'.split( '-' ); var month = dateParts[ 1 ];
var day = dateParts[ 0 ] ; var year = dateParts[ 2 ].split( ' ' )[ 0 ]; months[Number(month) - 1 ] + ' ' + day + ', ' + year;}
```
</details>

<details>
<summary>Export the content if the field is not empty; otherwise, display other text</summary>

```
%{( '${Focus}' .length >  0 ) ?  'Focus: ${Focus}' :  'Focus not Available' }
```
</details>


<details>
<summary>Support/Troubleshooting</summary>

If you have questions or technical issues, please [contact the Support team via the Customer Portal (Jira service management)](https://jira.getxray.app/servicedesk/customer/portal/2/user/login?destination=portal%2F2%2Fcreate%2F28) or [send us a message using the in-app chat](https://getxraydocs.atlassian.net/wiki/spaces/XRAYCLOUD/pages/44577312).
</details>