skybow SharePoint Apps
Expressions

Throughout the Actions Builder expressions can be used to dynamically calculate properties for the actions configured.

Expression Types

To cater for different uses any expression can be defined in any of the following forms: Template Expressions, Assignment Expressions, Function Code Expressions.

Template Expressions

Text templates are a special form of expressions in which placeholders are replaced by string representation (always returns a string, placeholders are always converted to string before inserted). Placeholders can contain field paths (e.g. [[@User.Email]]) or expression placeholders [[=new Date()]] (begin with equals sign).

This form allows to define textual values in a simpler, more abreviated and suitable manner than the other forms. As an example, we can write '[[Firstname]]  [[Lastname]]' for a calculation of a text field value, instead of needing the more complex value expression ('=[[Firstname]] + " " + [[Lastname]]').

 

Assignment Expressions

With assignment expressions you can define texts and values to be calculated using JavaScript-based assignment terms.

Function Code Expressions

Using function expressions more complex calculations can be defined. The expression allows using the full scope of JavaScript code as in bodies of JavaScript functions. Values must be returned using 'return <value>;' statements.

Expression Examples

Initially setting date time fields

= new Date() Set the current date time (can also be done just by using SharePoint default column value available in column's configuration)
= new Date(2014, 5, 3) Set the date to 3rd June 2014. Note: The month (2nd) parameter is 0-based, so January is 0 and December is 11.
= new Date().addDays(10) Set the date to current date (and time) plus 10 days. Use addDays(-n) to subtract n days.
= new Date().addHours(4) Set the date to 2 hours in future.
= new Date().addYears(-1) Set the date a year ago from today.

Calculating date time fields

=[[StartDate]] Get the date time field of another date time field. Note: Use Assignment expression when setting fields using calculated expressions.
=[[StartDate]].addDays(10) Get the date time field of the StartDate column plus 10 days.

{
 if ([[ContractType]] == "Monthly") 
  return [[StartDate]].addMonths(1);
 else if ([[ContractType]] == "Quarterly") 
  return [[StartDate]].addMonths(3);
 else if ([[ContractType]] == "Semi-Annually") 
  return [[StartDate]].addMonths(6);
 else if ([[ContractType]] == "Annually") 
  return [[StartDate]].addYears(1);
 else return null;
}

Get a date depending on value of field ContractType and StartDate. When ContractType is "Monthly" the date is calculated as StartDate plus 1 month, when ContractType is "Quarterly" the date is calculated as StartDate plus 3 months, etc. If ContractType does not match any of the checked values no date is returned.

 

As an example this function expression could be used as a calculated expression to set the RenewalDate field of a contract item.

Using JavaScript to define list item which is selected on list view

{

var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
return items.length == 1;

}

Check whether only one item is selected in the list (Can be used in Condition property.)

{

var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
if (items.length == 1)

  { return items[0].id; }
return null;

}

Returns Id of List Item which is selected on a view.

 

See Also