Skip to main content

setVar

setVar

Sets a value on a form variable (Form Var) predefined in the LucyStudio designer, from a form script.

Parameters

  • localVarName (string): A variable name predefined in the LucyStudio form settings
  • data (any): The value to set (string, number, boolean, object, and so on)

Returns: None (void)

Description

$form.setVar stores a value in a variable predefined per form in the LucyStudio designer. Internally it calls LucyVarMngr.setVarValue(_mapFormVar, localVarName, data).

The variable is valid only for the current form instance and is destroyed when the form closes. When the same form is opened as several instances, each instance has its own independent variable space.

warning

The variable name must be predefined in the LucyStudio designer. An undefined name simply won't work. Unlike setSharedData / setStoreData, you can't use arbitrary keys here.

$form vs $app vs $page

$form.setVar$app.setVar$page.setVar
ScopeCurrent form instanceShared app-wide❌ Not supported
Where it's predefinedLucyStudio form settingsLucyStudio app settings
LifetimeDestroyed when the form closesKept while the app runs
What clearVar resets toThe default given at declarationThe default given at declaration
Access from another form❌ No✅ Yes

Use $app.setVar when the value has to be shared app-wide.

Example

// LucyStudio에서 폼에 "count", "userName" 변수가 사전 정의된 경우
$form.setVar("count", 0);
$form.setVar("userName", "홍길동");
$form.setVar("selectedItem", { id: 1, name: "아이템1" });

// 값을 읽어서 사용
var count = $form.getVar("count");
$log.i("현재 카운트:", count);

Related

  • $form.getVar(localVarName) — reads a form variable
  • $form.clearVar(localVarName) — resets a form variable to its initial value
  • $app.setVar(appVarName, data) — sets an app-wide variable
  • $form.setSharedData(key, data) — stores in-memory data under an arbitrary key (no predefinition needed)