# Trigger CC from an App

{% hint style="info" %}
**Version Compatibility**

This feature is compatible with **v4.24** and later of the JourneyApps Container, and with **v1.0.0** and later of CloudCode.
{% endhint %}

CloudCode tasks can be called directly from an app and return the result.

The task will need to have the "App" trigger enabled in the configuration.

For example, given the task `echo_task`:

```javascript
export async function run(params) {
    console.log("params:", params);
    return {
        hello: "world",
        params
    };
}
```

When called from the app as follows:

```javascript
function callTask() {
    var task = "echo_task";
    var params = {
        "foo": "bar",
        "one": 1
    };
    var result = CloudCode.callTask(task, params);
    console.log("Result:", JSON.stringify(result));
    dialog(task, JSON.stringify(result));
}
```

Will produce the following result:

```json
Result: {"hello": "world", "params":{"foo":"bar","one":1}}
```

The ID of the user calling the task is available as `this.userId` in the task context (this value will be `null` if the task was not called from an app). The user object can then be loaded in the task as follows (assuming that the user is of type `user`):

```javascript
// load the user object of the mobile user that called the task, if the task was called by a user
// this assumes that the user model is `user`
if (this.userId) {
    const user = await DB.user.first(this.userId);
    console.log("user:", JSON.stringify(user));
}
```
