Userscripts

ReqEdit Online Documentation

Userscripts

3 min read
last updated: 02/15/2024

Execute your own javascript scripts on the currently opened ReqIF document. Mass update attributes conditionally or based on other attributes.

TLDR; Jump to example script

Javascript automation

ReqEdit userscript editor window with javascript code

Notices and limitations

The Javascript execution could produce unexpected results due to the fragile nature of Javascript engine.

Read only attributes cannot be updated.

If a value is invalid the attribute value will be empty.

HTML special characters will be converted to UNICODE so that   will be \u00A0, in regex replace use UNICODE character codes.

The javascript engine in ReqEdit is a basic javascript interpreter and does not have browser capabilities.

Script execution

The User scripts selector displays all the scripts found in ReqEdit scripts folder located at the current user’s %localappdata%\REQTEAM\ReqEdit\UserScripts\ folder.

From the editor window it is possible to quickly IMPORT and EXPORT these scripts.

The script selector is located at the right side of the toolbar

Select a script and then press to execute on all rows or to execute on only the selected row.

Run on document will be executed on each line from top to bottom according to the order in the hierarchy of the document.

Each row will have an index number represented by global.index variable (read on to find out more)

On each row you will be able to read all the columns and change them.

To save the changes to the current row use save(row)

Attribute type usage

TypeInformation
Booleanuse only the values: true, false without quotation marks
Stringupdate the value as “text in quotation marks”
Integerupdate with number
Dateupdate with a formatted string “yyyy-mm-ddThh-mm-ss
Enumeration single valuespecify the “value” case sensitive or “” to remove
Enumeration multi valuespecify as a “comma,separated” string case sensitive or “”
XHTMLupdate the value as “<strong>html codes</strong>”
Userscript attribute type usage

Javascript

Supports all ECMAScript 3 and ECMAScript 5 functionality, including ES5 strict mode

Read more about the supported Javascript features here Jurassic library

Variables

rowread/writeholds all attributes of the current row
row[“ReqIF.ChapterName”] is the value
row[“ReqIF.ChapterName.type”] is the attribute type
row[“ReqIF.ChapterName.status”] is New, Edited, EditedAndSaved, Unchanged, Deleted, SoftDeleted
linksreadin development
hasChildrenreadtrue/false if the row has children or not
globalreadmetadata of the current row or to be used to pass values between rows
global.indexreadthe number of the row in the selected rows starting from 1
global.levelreadthe level of the row starting from 1
global.statusreadthe status of the field: New, Edited, EditedAndSaved, Unchanged, Deleted, SoftDeleted
Javascript variables

Functions

log(string variable)display the contents of a single string variable to the output
save(row)IMPORTANT use this as the last line to save the row
Javascript functions

log(variable) will only work when the script editor window is open. The output messages are displayed in the bottom part.

User script editor displaying output text

Example script

  1. Create a document by selecting File > New > New Archive …
  2. Select ReqEdit JS Demo template and save the file (the name is not important)
  3. Select the ReqEdit JS Demo script
    (If by any means the ReqEdit JS Demo script is not available create it manually, jump to create scripts and use the example script from below)
  4. Press Run on document
  5. Observe the change of the ReqIF-WF.CustomerStatus value to Accepted
  6. Read more in the the ReqIF Info panel
ReqIF Info panel describing the reqif template for the ReqEdit JS Demo

The script

Change a value conditioned by another value

if(row["ReqIF-WF.Type"] == "Requirement"){
	row["ReqIF-WF.CustomerStatus"] = "Accepted"
}
save(row);

Explanation

1.Using the if(<logical condition>){ … } control statement

2.Test the <logical condition> where ReqIF-WF.Type column value is equal to Requirement

3.If the logical condition is true then execute the code betwen { … }

4.Change the value of ReqIF-WF.CustomerStatus value to Accepted

5.Save the changes for the current row by calling save(row)

Without save(row) the changes are not applied to the document

Creating or modifying scripts

You can create new scripts by selecting empty on the script selector then pressing the edit button

Save the script with a descriptive name

The script will then be displayed in the dropdown automatically to be executed easily