Skip to content

context.UserData

Overview

Provide the ability to share data between "Server Script".

Properties

Since it is an ExpandoObject, you can add properties with any name.

Methods

There are no methods.

Usage Examples

In the example below, the first server script stores the information retrieved from the database in the user data MyData, and the second server script outputs the number of data items stored in the user data MyData to the log. The first condition is checked as "Before Update" and the second as "After Update".

JavaScript
// First server script
let results = items.Get(10);
context.UserData.MyData = results;
JavaScript
// Second server script
let results = context.UserData.MyData;
context.Log(results.Length);

Code Samples

1. Color rows on the index screen by comparing them with the average

On the index screen, get the average of an arbitrary numeric column in the table, and color each row depending on whether the record's value is lower or higher than the average.

Also, since the average only needs to be calculated once when the screen is displayed, it is stored in UserData and carried over to avoid unnecessary calculations.

JavaScript

Condition: Before opening the row

// Carry over the average in UserData
if (!context.UserData.average) {
    context.UserData.average = items.Average(context.SiteId, 'NumA');
}
// Change the row color by comparing with the average
if (context.UserData.average < model.NumA) {
    model.ExtendedRowCss = 'high';
} else {
    model.ExtendedRowCss = 'low';
}
CSS

An example of the CSS settings.

1
2
3
4
5
6
7
8
/* Higher than the average */
.high td:not(:nth-child(0)) {
    background-color: rgb(235, 175, 175);
}
/* Lower than the average */
.low td:not(:nth-child(0)) {
    background-color: rgb(185, 220, 246);
}

Supported Versions

  1. Pleasanter 1.1.13.0 or later
  2. Pleasanter .NET Framework version 0.50.219 or later