Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


On this page:

Table of Content Zone

Table of Contents


Basic Usage


The Action script contains instructions that will be executed when calling an action. If you're not yet familiar with SIL, see Simple Issue Language™ usage.

...

Anchor
ValidatingScreenFields
ValidatingScreenFields

Action Script 

Once you have a screen that requires an additional user input, it is necessary to validate that input and let the user know if they did something wrong. This can be done by returning values from the script.

...

Code Block
string fruitLabel = getElement(argv, 0);
string fruit = getElement(argv, 1);

string chocolateLabel = getElement(argv, 2);
string chocolate = getElement(argv, 3);

string [] errors;

if( isNull(fruit) ){
 	errors = addElement(errors, fruitLabel);
	errors = addElement(errors, "What? You don't like fruits?");
}

if( chocolate != "yes" and chocolate != "of course"){
	errors = addElement(errors, chocolateLabel);
	errors = addElement(errors, "No way!");
}

return errors;

Redirecting and Preventing Refresh

Since version 4.5.5, Power Actions got the ability to redirect to some random page and also to prevent refresh. For this to happen, the return of the action should be of predefined type BActionReturn,  which is defined as having the following fields:

  1. errors, array of BActionError (see below)
  2. location, string, represents the potential URL to redirect to, leave empty if you want to avoid redirection
  3. disableRefresh, a boolean, which, if set, will prevent the refresh to be automatically executed at the end of the action

BActionError is a simple structure, containing just two fields:

  1. field, string, the field is question, leave empty if you want a global error message
  2. message, string, containing the message, probably you should put something here.


Resolution on the screen is performed in the usual way, if there are errors added in the return, the processing will stop and errors will be shown on the screen. If the location field is filled and there are no errors, a redirect will happen. If the location is empty but the disableRefresh flag is set, the screen will not be refreshed, as usual. This may come in handy when integrating with certain 3rd party addons.

Code Block
//example excerpt:
................

BActionReturn ret;

if(thereAreErrors()) {
  BActionError e;
  e.message = "There are errors!"; //global
  ret.errors += e;
} else if(mustRedirect()) {
  ret.location = "https://google.com?q=SIL";
} else {
  ret.disableRefresh = true;
}

return ret;


We recommend you to use the structure above whenever possible, although the old way is still available (i.e. old scripts do not need to change).


Example

Iterating over uploaded files:

...