> For the complete documentation index, see [llms.txt](https://4wsplatform.gitbook.io/knowledge-base/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://4wsplatform.gitbook.io/knowledge-base/executing-sql-statements-from-within-an-action.md).

# Executing SQL statements from within an action

Inside a server-side javascript action it is possible to execute SQL statements (SELECT, UPDATE, etc…). In order to to that, the executeSQL instruction must be used.

In case of a SQL SELECT query (for instance to feed a grid report), the executeQuery method must be used instead:

```javascript
var vo_par = new Object();

/* Note that the parameters here are expressed in camel mode (COMPANY_ID -&gt; companyId) */
vo_par['par1']=vo['par1'];
vo_par['par2']=vo['par2'];


/* Encode the parameters array into a JSON string */
json = Ext.encode(vo_par);


var url = contextPath + '/executesql/executequery?appId=' + applicationId + '&amp;applicationId=' + applicationId + '&amp;compId=XXX';

var response = new SyncRequest().send(url, 'POST', json, 'application/json');

if (response != null &amp;&amp; response != '') {
 risp = Ext.decode(response);

 if (risp['success'] == false) {
 showMessageDialog("dialog.title.error", risp['message'], function() {}, false);
 return false;
 }else{
 /* here it is possible to scroll along the value objects list (which is an array) */
 var obj=risp.valueObjectList[0].NOME_TABELLA;
 }
}
```

In case of a SQL statement like INSERT, UPDATE, DELETE, the right method is executeSQL:


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://4wsplatform.gitbook.io/knowledge-base/executing-sql-statements-from-within-an-action.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
