Vendors API Example Plugin
This example demonstrates how to integrate a Jira custom field with the Behaviours API. You can download the source code from GitHub. You'll also need the latest version of ScriptRunner for Jira (8.14.0 or above) for the integration to work.
There are three stages to working with this example plugin:
Compile the example plugin
- Run
atlas-mvn
package
at the root of the project.
This step provides a plugin JAR file in thebackend
/target
directory. Install the provided JAR file in your local Jira instance.
Troubleshooting
If the above steps do not work, do npm install
and npm run build
in the /frontend
folder before you run atlas-mvn package
at the root of the project. This steps makes sure the latest frontend code is bundled in the .jar.
Configure a custom field
- In your local Jira instance, go to Issues > Custom fields.
- Select Add a custom field.
- Select the SR Vendors API Select Example or SR Vendors API Example, and name it
Vendors API
. - Add the new custom field to a chosen project screen. You can now access the field in the Issue Create modal.
Test
When our custom field is visible on the Issue Create modal, we can configure Behaviours to test the implementation.
Navigate to the ScriptRunner Behaviours page and configure the new Behaviour.
Map the Behaviour to All Issue Projects and All Issue Types.
Testing the setting value
To test the setting field value, we'll use an Initialiser script.
Navigate to the ScriptRunner Behaviours page and configure the new Behaviour.
- Name the Behaviour
Test setting value
. Map the Behaviour to All Issue Projects and All Issue Types.
Select Create Script under Initialiser and add the following script:
getFieldByName('Vendors API').setFormValue('value from Behaviour initialiser')
- Save the Behaviour.
- Open the Create Issue modal and verify that the initial value for the field was set.
Testing the getting value
We are aware this example does not currently work with some fields. We are working on this and will fix this issue as soon as possible.
To test the getting value, we’ll get the value from our custom field and set it as an issue description when Summary is edited. To achieve this, we need to add the Summary field to our Behaviour and key in a script:
Navigate to the ScriptRunner Behaviours page and configure the new Behaviour.
- Name the Behaviour
Test getting value
. Map the Behaviour to All Issue Projects and All Issue Types.
- Under Add Field, select Summary.
- Select Add.
Select Create Script and add the following script:
def fieldValue = getFieldByName('Vendors API').getFormValue() getFieldByName('Description').setFormValue(fieldValue)
- Open the Create Issue modal.
- Change the value of Vendors API field, then change the value of the Summary field.
Observe how Description was also set.
Testing handling user changes
Test handling user change by adding a Behaviour to the Vendors API field:
Navigate to the ScriptRunner Behaviours page and configure the new Behaviour.
- Name the Behaviour
Test handling user changes
. Map the Behaviour to All Issue Projects and All Issue Types.
- Under Add Field, select Vendors API.
- Select Add.
Select Create Script and add the following script:
def userValue = getFieldByName('Vendors API').getFormValue() getFieldByName('Description').setFormValue("User value: ${userValue}")
- Open the Create Issue modal.
- Change the value of Vendors API field.
Observe how Description was also changed.
Testing read-only status
Test the read-only status by changing the script for the Summary field in the Test getting value Behaviour:
Navigate to the ScriptRunner Behaviours page.
Map the Behaviour to All Issue Projects and All Issue Types.
- Locate the Test getting value Behaviour and select Edit.
Update the Summary field script to the following:
def summaryValue = getFieldByName('Summary').getFormValue() getFieldByName('Vendors API').setReadOnly(summaryValue == 'read-only')
- Open the Create Issue modal.
- Type
read-only
into the issue Summary field.
Observe that the Vendors API field becomes read-only. If any other value is entered into the Summary field, observe that the Vendors API field can still be modified.