Availability
This routine is available since
- JJUPIN 2.5
- katl-commons 2.5
Syntax
lfWatch(field, relatedFields, scriptPath[,javaScriptEvents]);
Description
Attach listeners for the events that you give as parameters in the function.
If you don’t give any event, it attaches listeners to “change” event (triggered when the issue is updated).
Every time the event is triggered, the SIL script from scriptPath parameter runs.
This SIL script receives the values for the relatedFields and you can use them as: argv[field].
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
field | String | Yes | The field to listen. |
relatedFields | Array String | Yes | The dependent fields required for the given field. |
scriptPath | String | Yes | The script source to run when the event is triggered. |
javaScriptEvents | Array | No | The events to listen to. It's any JavaScript event (check this list for references) |
"change" event
When using the "change" event on a "labels type" field (Fix Versions, Affected Versions, Labels, Components, etc.), the event will never trigger when a label is deleted, but only when labels are added. We have noticed that for these fields the "focusin" event closely matches the behavior expected for the "change" event.
Example
lfWatch("summary", {"summary", "customfield_13706","components"}, " hook.sil", {"keyup"}); //where field = "summary";relatedFields = {"summary", "customfield_13706","components"};scriptPath = " hook.sil";javaScriptEvents = {"keyup"}
For the scriptPath parameter you can either give the relative path (as in the example above), or the absolute path as: "C:/Program Files/Atlassian/Application Data/JIRA/silprograms/hook.sil".
// hook.sil : if (contains(argv["summary"], "important")) { lfSet("priority", "Critical"); lfShowFieldMessage("priority", "Priority changed", "INFO"); }
Every time when the keyup event is triggered, the hook.sil is executed. When the summary field contains the word “important”, priority field is set to Critical and a message will be displayed for the priority field.
The first image shows the initial value of the priority for the current issue, the next one shows the value it is changed to, after executing the code from hook.sil.
As we said before, the values from the relatedFields are accessed as argv[field]. For multiple values fields like components or affectedVersions the value returned is in the following format: val1|val2|val3.
Info
For more information, see How 'Live Fields' work.