Userscripts
3 min read
last updated: 03/18/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
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
- Updating a multi-object-type document can update all attributes values. Use the ReqEdit.ObjectType to limit what object type attributes to set
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
Type | Information |
---|---|
Boolean | use only the values: true, false without quotation marks |
String | update the value as “text in quotation marks” |
Integer | update with number |
Date | update with a formatted string “yyyy-mm-ddThh-mm-ss“ |
Enumeration single value | specify the “value” case sensitive or “” to remove |
Enumeration multi value | specify as a “comma,separated” string case sensitive or “” |
XHTML | update the value as “<strong>html codes</strong>” |
Javascript
Supports all ECMAScript 3 and ECMAScript 5 functionality, including ES5 strict mode
Read more about the supported Javascript features here Jurassic library
Variables
row | read/write | holds 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 |
links | read | in development |
hasChildren | read | true/false if the row has children or not |
global | read | metadata of the current row or to be used to pass values between rows |
global.index | read | the number of the row in the selected rows starting from 1 |
global.level | read | the level of the row starting from 1 |
global.status | read | the status of the field: New, Edited, EditedAndSaved, Unchanged, Deleted, SoftDeleted |
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 |
log(variable) will only work when the script editor window is open. The output messages are displayed in the bottom part.
Example script
- Create a document by selecting File > New > New Archive …
- Select ReqEdit JS Demo template and save the file (the name is not important)
- 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) - Press Run on document
- Observe the change of the ReqIF-WF.CustomerStatus value to Accepted
- Read more in the the ReqIF Info panel
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