# methodCall

## Description

Runs the method using the object assigned in context parameter.

## Input / Parameter

| Name      | Description                                               | Input Type | Default | Options | Required |
| --------- | --------------------------------------------------------- | ---------- | ------- | ------- | -------- |
| context   | This is the context (object) that the method will run on. | Object     | -       | -       | Yes      |
| method    | The method to run or call.                                | Object     | -       | -       | Yes      |
| arguments | The arguments that will be passed to method.              | Array/List | -       | -       | Yes      |

## Output

| Description                                                                                                                                                                              | Output Type |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| The return type of methodCall depends on the function that is passed as the method. Specifically, it will return the result of invoking the method with the given context and arguments. | Any         |

## Example

In this example, we will use function `methodCall` to add a new div element in the document body by getting `document` object using `resolveJSName` function.

### Code Equivalent

```
// Create div element
var div = document.createElement("div");

// Add some attribute to the div
div.className = "class";

// Add to the body
document.body.appendChild(div);
```

### Steps

1. Drag a `button` component into the canvas and open the `Action` tab. Select the `press` event of the button and drag the `setVar` function to the event flow.
2. On `setVar` function `var` param add `div` as the value and on it's `value` param add a subflow and drag a function `methodCall`.
3. On it's `context` param add a subflow and drag a function `resolveJSName`, on it's `name` param add the value `document`.

   ![](/files/26cPRzeYSgrWYT7KkhRm)
4. On it's `method` param add a subflow and drag a function `objectAttr`, on it's `object` param add a subflow and drag a function `resolveJSName`, on it's `name` param add the value `document`. Back on the function `objectAttr` on it's `attr` param add the value `createElement`.

   ![](/files/DBHxI5F2G4cIZiy5FXhr)
5. On it's `arguments` param add a subflow and drag a function `toArray`, on it's `value1` param add the value `div`.

   ![](/files/uGbzMco3SS7jwxxrAIbD)
6. Back to main flow, drag the `setObjectAttr` function to the event flow, on it's `object` param add a subflow and drag a function `getVar`, on it's `var` param add the value `div`. As for the `attr` param add the value `className` and for the `value` param add the value `class`.

   ![](/files/k45dhaJfaOJMpCdNEFEg)
7. Back to main flow, drag the `methodCall` function to the event flow, on it's `context` param add a subflow and drag a function `resolveJSName`, on it's `name` param add the value `document.body`.

   ![](/files/X1JFQclqYcniXtWBmTpv)
8. On it's `method` param add a subflow and drag a function `objectAttr`, on it's `object` param add a subflow and drag a function `resolveJSName`, on it's `name` param add the value `document.body`. Back on the function `objectAttr` on it's `attr` param add the value `appendChild`.

   ![](/files/jNwYasiBLtJUv2ub0UeW)
9. On it's `arguments` param add a subflow and drag a function `toArray`, on it's `value1` param add a subflow and drag a function `getVar`, on it's `var` param add the value `div`.

   ![](/files/KK3yHz26Zw7Pdy3rKXZL)

### Result

1. Now click the button in preview, check the inspector, you will see a new div element being added on the body

   ![](/files/Ka5ooeyqKe0d53N6pDg2)

## Links

### Related Information

See also:

* Functions
  * [resolveJSName](/emobiq-client/006-actions-and-visual-logic/action-reference/cordova/app/resolvejsname.md)


---

# Agent Instructions: 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://docs.emobiq.com/emobiq-client/006-actions-and-visual-logic/action-reference/cordova/app/methodcall.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.
