🆕set
To update a value of a given field
This function updates a field and its value. You can use set
to modify a field by specifying its name or ID as text, such as "Name" or "A."
Syntax
set(nid, string, any)
Return
void
Benefits of set
set
Easy to update: The
set
function makes it easy to update multiple fields without writing a lot of repetitive script. This is especially helpful when you have many fields to handle.Easy maintenance: Since you don't have to hardcode each field name, your scripts are easier to maintain and update. If field names change or new fields are added, you can adjust your script more easily.
More flexibility: You can dynamically reference fields by their names or IDs, which makes your scripts more adaptable. This is useful if your data structure changes or if you're working with different data sources that have different fields.
Using set
can help you manage your data more efficiently in Ninox, making the process smoother and reducing the likelihood of errors.
Examples
Use
set(nid, fieldName, text)
to set the field named "Name" to the value "Vania" using the current table's record ID (nid
) and text:
Return: void
Use
set(nid, fieldName, number)
to set the field named "Age" to the value "42" using the the current table's record ID (nid
) and a number:
Return: void
Use
set(this, fieldName, boolean)
to set the field named "isActive" to the value "true" using the current table's record ID (nid
) and a boolean value:
Return: void
Traditional method
In a typical scenario, you might have an API response with a list of records. For example:
To create these records in Ninox, you might traditionally use:
The traditional method requires you to specify each field individually. As the number of fields increases, your script grows and becomes more complex. With set
, your script stays concise and manageable, regardless of how many fields you have.
Dynamic field updates with set
set
The set
function simplifies this process by allowing you to iterate over the fields dynamically. Here’s how you can use it:
See also
get
which returns a value of a given field.
Last updated