# Operation utils

### Operation

The `operation` object is the main object for executing operations.

#### operation.execute(operationConfig)

Execute selected operation to received identifier.

**Returns**: void

This function takes as parameter an object with the following fields:

| Property            | Type   | Default                 | Mandatory | Description                                                                                                                                                                                                                           |
|---------------------|--------|-------------------------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| subEntityIdentifier | String |                         | No        | You can execute operation on device, subscription or subscriber identifier. With _subEntityIdentifier_ you define selected identifier. **Default**: If is undefined it will open on _provision.administration.identifier_ identifier. |
| operationType       | String |                         | Yes       | Operation Identifier. You can get this values getting operation catalog. **Mandatory field**. The rule will be created, but the operation will not.                                                                                   |          
| operationTimeout    | Number | 60000                   | No        | Operation timeout in milliseconds.                                                                                                                                                                                                    |            
| jobUser             | String |                         | Yes       | User apiKey that launch this operation. **Mandatory field**. The rule will be created, but the operation will not.                                                                                                                    |        
| retries             | Number | 0                       | No        | Operation retries number.                                                                                                                                                                                                             |   
| ackTimeout          | Number | null                    | No        | ACK timeout in milliseconds.                                                                                                                                                                                                          |
| retriesDelay        | Number | 0                       | No        | Delay in seconds between retries.                                                                                                                                                                                                     |
| stopValue           | String | operationTimeout + 5000 | No        | Stop value, this value depends of stop mode selected.                                                                                                                                                                                 |
| stopMode            | String | delayed                 | No        | Stop mode. Possible values are: **date**: If this mode is selected, stop value is a date in YYYY-MM-DDThh:mm:ssTZD format. **delayed**: If this mode is selected, stop value is a time defined in milliseconds.                       |
| parameters          | Object | {}                      | No        | This value is a json with accepted value in selected operation. You can see parameters getting operation catalog.                                                                                                                     | 
| callback            | String | null                    | No        | URI where the result of the operation execution is received.                                                                                                                                                                          |

**NOTE**: The Job of the operation will be created with an active status by default.

Example of use:

The example execute _ADMINISTRATIVE_STATUS_CHANGE_ operation to received device.

```javascript
operationConfig = {
    subEntityIdentifier: entity['provision.administration.identifier']._value._current.value,
    operationType: 'ADMINISTRATIVE_STATUS_CHANGE',     
    operationTimeout: 20000,   
    jobUser: apiKey,           
    retries: 1,            
    ackTimeout: 5000,        
    retriesDelay: 0,      
    stopValue: '25000',         
    stopMode: 'delayed',
    callback: 'http://127.0.0.1:7070/directory',
    parameters: {
        admsts: 'BANNED'
    }
}

operation.execute(operationConfig);
```

Another example with stopMode = date

```javascript
operationConfig = {
    subEntityIdentifier: entity['provision.administration.identifier']._value._current.value,
    operationType: 'REFRESH_PRESENCE',     
    operationTimeout: 20000,   
    jobUser: apiKey,           
    retries: 1,            
    ackTimeout: 5000,        
    retriesDelay: 0,      
    stopMode: 'date',
    stopValue: '2045-11-08T08:30:00+02:00',
    callback: 'http://127.0.0.1:7070/directory',
    parameters: {}
}

operation.execute(operationConfig);
```
