---
title: "EWset Module"
canonical: "https://help.agiloft.com/space/HELP/43714623/EWset+Module"
format: markdown
---
## > Macro (anchor)

<span style="color: #00306e">EWset::save($outfileName)</span>

Processes changes requested by the user and stores them in an xml file.

You should call this method at the end of your script to make your changes available to Agiloft. For example, the script may have changed the value of a field, this change will be ignored, unless it calls "save" prior to exiting.

> ℹ️ **Example**
> ℹ️ 
> ℹ️  If you used 
> ℹ️ 
> ℹ️ ```perl
> ℹ️  my ($input_fname, $output_fname) =@ARGV;
> ℹ️ ```
> ℹ️ 
> ℹ️   
> ℹ️ at the start of your script to extract commandline params, then use 
> ℹ️ 
> ℹ️ ```perl
> ℹ️  EWget::save($output_fname);
> ℹ️ ```
> ℹ️ 
> ℹ️   
> ℹ️ to save your changes.


<span style="color: #00306e">EWset::setRecordField($fieldName, $fieldValue)</span>

Assigns a value to the specified field in the record or sets the field to NULL if the value is undefined.

> ℹ️ **Example**
> ℹ️ 
> ℹ️  To set the value of the "email" field in the current record 
> ℹ️ 
> ℹ️ ```perl
> ℹ️ EWset::setRecordField("email",
> ℹ️ "myemail@example.com"); 
> ℹ️ ```
> ℹ️ 
> ℹ️ *Comment*  
> ℹ️ This is the core function for change data in a your script.  
> ℹ️ This function manipulates both common fields and linked fields.

See [Stringifiers Description](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43714635) for full description of acceptable formats for each type of data.

See also [Linked Fields in Scripts](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43714545) chapter for more information.

## EWSet::setExitAction($exitAction)

Determines what happens when the script exits. Option parameters are enclosed in double quotation marks.

Allowed options are:

- **"AcceptChanges"** - the record is updated in the normal fashion. You can use setMessage to inform user about the details of update.
- **"RejectChanges"** - the modification is rejected. User will be shown the record editing window, if the action was initiated via web interface.
- **"RejectChangesAndExit"** - the modification is rejected and the user is automatically logged out. After logout, user will be redirected to URL specified by setRedirect function call.
- **"AcceptChangesAndExit"** - the record is updated in the normal fashion and the user is automatically logged out. After logout, user will be redirected to URL specified by setRedirect function call.

### Alternative to setExitAction

As an alternative to setExitAction, provided for compatibility with languages that do not allow strings to be returned, the script can provide an exit (return) code.

- If the exit code is 0, the record is updated in the normal fashion. You can use setMessage to inform user about the details of update.
- If the exit code is 1, the modification is rejected. User will be shown the record editing window, if the action was initiated via web interface.
- If the exit code is 2, the modification is rejected and the user is automatically logged out. After logout, user will be redirected to URL specified by setRedirect function call.
- If the exit code is 3, the record is updated in the normal fashion and the user is automatically logged out. After logout, user will be redirected to URL specified by setRedirect function call.

Formally speaking this function sets the value for the tag 'exitAction'.

## EWset::setMessage($userMessage)

Send a message to the user.

This message will be shown to the user if the script is executed because the user has changed a record in GUI. Formally speaking, this method sets the value for the tag 'message'.

> ℹ️ **Example**
> ℹ️ 
> ℹ️ ```perl
> ℹ️ EWset::setMessage("Select yes to accept
> ℹ️ end-user agreement and create new account")
> ℹ️ ```

When a script blocks a record edit, it is a good practice to use setMessage to explain why the change was blocked and what the user should do. Of course, it can also be used to confirm success or provide some other message.

## EWset::setRedirect($redirectUrl)

Sets the value of the URL that the user should be directed to if the script logs them out of Agiloft

The redirect URL should be absolute and include "http". It will be opened in the same browser window. Formally speaking, this method sets the value of the tag 'redirect'.

> ℹ️ **Example**
> ℹ️ 
> ℹ️ ```perl
> ℹ️ EWset::setRedirect("http://www.enterprizewizard.com")
> ℹ️ ```

It is useless to call setMessage() with setRedirect since there will be no Agiloft page shown to display the message.

## EWset Debug Functions

The following functions are mostly used for debugging scripts. 

```perl
EWset::setDebug($debugMessage)
```

Write to the log file (formally speaking, sets value for tag 'debug').

This message is saved to the Agiloft log. It can be useful for logging the result of a script or to debug the script.

## EWset::setReport($reportMessage)

Sets a value in the record history

This message is stored in the record history. Formally speaking, this method sets the value for the tag 'report'.

Note: It is sometimes helpful to write a description of what the script did to the data and why.

## EWSet::exit_ew ($exitAction, $outfileName)

Combination of functions EWSet::setExitAction($exitAction) and EWset::save($outfileName) with the same arguments and meanings.

> ℹ️ **Example**
> ℹ️ 
> ℹ️ The function is able to get an exitCode directly, as $exitAction argument, thus the following pairs of values are equivalent:   
> ℹ️  
> ℹ️ 
> ℹ️ "AcceptChanges" or 0 or "0"  
> ℹ️  
> ℹ️ 
> ℹ️ "RejectChanges" or 1 or "1"  
> ℹ️  
> ℹ️ 
> ℹ️ "RejectChangesAndExit" or 2 or "2"  
> ℹ️  
> ℹ️ 
> ℹ️ "AcceptChangesAndExit" or 3 or "3"

> Macro (hide-if)
> 
> #### Related articles
> 
> > Macro (contentbylabel)