Behaviours API
You can reference the functions and properties outlined below within your behaviour scripts.
Read/Update fields
Access a field
All supported fields can be accessed by using getFieldById(fieldID).
For example:
jsconst theDescription = getFieldById("description") theDescription.setName("The description name"); const theValue = "the value is " + theDescription.getValue(); logger.info(theValue);
Accessing custom fields
Custom fields cannot be accessed by their field name and instead have to be accessed by their ID e.g customfield_01232
The ID of the custom field can be found by either utilising the Jira Cloud REST API to make a request to the field endpoint https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-fields/#api-rest-api-3-field-get such as https://YOUR_ATLASSIAN_INSTANCE/rest/api/3/field
When selecting a custom field as the affected field, the custom field ID will display at the top of the Create modal screen.
Access a changed field
If your script is triggered onChange you can use the getChangeField() function. This function will return an object with the same structure as getFieldById.
For example:
jsconst changedField = getChangeField() if(changedField.getName() == "summary") { logger.info("The summary has changed!"); }
Available Read Methods
It is important to note that these methods are only accessible on the object returned by getFieldById.
The usage of the getValue and setValue methods has changed for several fields as the displayName
property has been deprecated. The examples outlined below show how these now work.
For the assignee, userPicker and multiUserPicker fields, only accountIds are returned as the displayName property is no longer available. Scripts that rely on displayName
information will break; instead, you will now have to make a request to /rest/api/3/user?accountId=
and/or $
{accountId}/rest/api/3/bulk?accountId==
$
{idsToFetch.join("&accountId=")}.
For single and multiselect, you must now use the value
property instead of the deprecated name
property.
getContext
Returns the context details provided by Atlassian when a behaviours script is run.
Return Type: Object
{
localId: string,
cloudId: string,
enviroment: string,
moduleKey: string,
siteUrl: string,
accountId: string,
licence: string,
timeZone: string,
extension: {
viewType: string,
issueType: {
id: string,
name: string
},
project: {
id: string,
key: string,
type: string
}
}
}
Note: When a behaviour is run on the Issue View inside the extension property of the context object, then there is an issue object with the structure, as shown below.
issue: {
id: string,
key: string,
}
jsconst context = await getContext()
Access the user that loaded the screen by account ID.
jsconst context = await getContext() context.accountId
Access the project key of the current project.
jsconst context = await getContext() context.extension.project.key
Access the ID of the current issue type.
jsconst context = await getContext() context.extension.issueType.id
Access the current issue key when on an issue view
jsconst context = await getContext() context.extension.issue.key
getDescription
Returns the description of the field
Return type: String
jsgetFieldById("summary").getDescription()
getId
Returns the id of the field
Return type: string
jsgetFieldById("summary").getId()
getName
Returns the name of a field
Return type: String
jsgetFieldById("summary").getName()
getOptionsVisibility
Returns the options that are visible for a field.
This method can only be used after setOptionVisiblity has been called; otherwise, it may be returned as undefined.
Return Type: Object
{options: Array<string>, isVisble: boolean}
Supported Fields:
- Priority
- Issue Type
- Select List Fields
- Multi-Select List Fields
- Checkbox Fields
jsgetFieldById("priority").getOptionsVisibility()
jsgetFieldById("issuetype").getOptionsVisibility()
Note: This method works for On Change events only and always returns undefined for On Load events.
getType
Returns the type of the field.
Return type: string
jsgetFieldById("summary").getType()
getValue
Returns the value of a field. The return type depends on the field you’re updating:
- Cascading Select:
type:null | { parent: { id: string; value: string };
child: { id: string; value: string } | null;
}
jsgetFieldById("customfield_10035").getValue() // example return value Parent 1 - Child 1.1
Original Estimate:
type:number|null
jsconst originalEstimateField = getFieldById("timeoriginalestimate"); originalEstimateField.getValue(); //example return value 4 | null
Summary:
type:string
jsgetFieldById("summary").getValue()
Description:
type:string | ADF
// We return a string or ADF (Atlassian Doc Format), depending on your Jira configuration type ADF = { version: 1, type: 'doc', content: Node[] }
More details about ADF: https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/
Labels:
type:string[]
PriorityField
type:{id: string, name: string, iconUrl?: string, }
jsconst priority = getFieldById("priority"); priority.getValue(); //example return value {id: "12345", name: "test"}
AssigneeField
type:null | { accountId: string, }
jsconst assignee = getFieldById("assignee"); assignee.getValue(); //example return value {accountId: "dfqsw43ref"}
ReporterField
type:null | { accountId: string, }
jsconst reporter = getFieldById("reporter"); reporter.getValue(); //example return value {accountId: "dfqsw43ref",}
FixVersionsField
type:{ id: string, name: string }
jsconst fixVersions = getFieldById("fixVersions"); fixVersions.getValue(); //example return value {id: "1234", name: "version One"}
ComponentsField
type:{ id: string, name: string }
jsconst components = getFieldById("components"); components.getValue(); //example return value {id: "1234", name: "Component One"}
IssueTypeField =
type:{ id: string, name: string }
jsconst issueType = getFieldById("issuetype"); issueType.getValue(); //example return value {id: "1234", name: "Task"}
Parent Field
type: { id: "10001", key: "DEMO-1000" } | nulljsconst parentField = getFieldById("parent"); parentField.getValue(); //example return value { id: "10001", key: "DEMO-1000" } | null
Custom SelectField
type:null | {id: string, value: string,}
jsconst singleSelect = getFieldById("customfield_01231"); singleSelect.getValue(); //example return value {id: "12345",value: "helloWorld",}
Custom MultipleSelectField
type:{ id: string, value: string,}[]
jsconst multipleSelect = getFieldById("customfield_01232"); multipleSelect.getValue(); //example return value [{id: "12345", value: "helloWorld",}, {id: "67890",value: "fooBar",}]
Custom UserPickerField=
type:null | { accountId: string,} }
jsconst userPicker = getFieldById("customfield_10984"); userPicker.getValue(); //example return value {accountId: "394urfjj9r2",}
Custom MultiUserPickerField
type:{accountId: string }[]
jsconst userPicker = getFieldById("customfield_10984"); userPicker.getValue(); //example return value [{accountId: "394urfjj9r2",},{accountId: "432-jftpwer0",},]
Custom paragraph
type:ParagraphField
// string is for Plain-text editor // Rich-text editor (ADF format) type ParagraphField = { string | ADParagraphField }
More details about ADF: https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/
- Custom text field
type:string
Custom checkbox fields
type:{ id: string, value: string,}[]
jsconst checkboxValue = getFieldById("customfield_02133").getValue(); //example return value [{"id":"10021","value":"A"},{"id":"10022","value":"B"}]
Custom Radio Buttons Field
type:string | null
jsconst radiobutons = getFieldById("customfield_02134").getValue(); //example return value "10021"
Custom Url Field
type:string | null
jsconst url = getFieldById("customfield_02135").getValue(); //example return value "https://www.adaptavist.com"
Custom Date Picker Field
type:string | null
jsconst date = getFieldById("customfield_02136").getValue(); //example return value "2023-11-14"
Custom Date Time Picker Field
type:string | null
jsconst dateTime = getFieldById("customfield_10035”).getValue(); //example return value "2024-03-13T15:30+03:00"
Custom URL Field
type:string | null
jsconst url = getFieldById("customfield_02137").getValue(); //example return value "https://adaptavist.com"
Custom Number Field
type:string | null
jsconst number = getFieldById("customfield_02138").getValue(); //example return value 100
Status
type:{id: string, name: string }
js// returns StatusField const statusField = getFieldById("status"); statusField.getValue(); //example return value {id: "12345", name: "test"}
Affects versions
type:{id: string, name: string }
js// returns Affects versions const versions = getFieldById("versions"); versions.getValue(); //example return value {id: "10001", name: "2"}
Due date
type:string | null
js// returns due date const dueDate = getFieldById("duedate").getValue(); //example return value "2024-11-05"
Target start date
type:string | null
js// returns target start date const targetStart = getFieldById("customfield_10022").getValue(); //example return value "2024-11-05"
- Target end date
type:string | null
js// returns target end date const targetEnd = getFieldById("customfield_10023").getValue(); //example return value "2024-11-05"
isCreateView
Returns whether or not the current view is the Create View.
Return type: boolean
jsif(isCreateView()){ getFieldById("summary").setValue("This code works only on the Create View"); }
isIssueView
Returns whether or not the current view is the Issue View.
Return type: boolean
jsif (isIssueView()){ getFieldById("summary").setValue("This code works only on the Issue View") }
isReadOnly
Returns whether the field has been set as read-only.
Return type: boolean
jsgetFieldById("summary").isReadOnly()
isRequired
Returns whether or not the field is required.
Return type: boolean
jsgetFieldById("summary").isRequired()
isVisible
Returns whether the field has been hidden.
Return type: boolean
jsgetFieldById("summary").isVisible()
Available Write Methods
It is important to note that these methods are only accessible on the object returned by getFieldById
and getChange.
The usage of the getValue and setValue methods has changed for several fields as the displayName
property has been deprecated. The examples provided in the table below show how these now work.
For the assignee, userPicker and multiUserPicker fields, only accountIds are returned as the displayName property is no longer available. Scripts that rely on displayName
information will break; instead, you will now have to make a request to /rest/api/3/user?accountId=
and/or $
{accountId}/rest/api/3/bulk?accountId==
$
{idsToFetch.join("&accountId=")}.
For single and multiselect, you must now use the value
property instead of the deprecated name
property.
setDescription(desc)
Updates the field description.
Parameter: desc
Parameter type: string
jsgetFieldById("summary").setDescription("A new description")
setName(name)
Updates the field name.
Parameter: name
Parameter type: string
jsgetFieldById("summary").setName("A new name")
setOptionVisibility(options,isVisible)
Updates the values that are selectable in a field.
Parameter: options
Parameter type: Array<string>
- Strings of the option value IDs
Parameter: isVisible
Parameter type: boolean
Note: setting isVisible
to true shows the specified option values in the field only, whereas false hides the specified option values in the field.
jsgetFieldById("priority").setOptionsVisibility(["1","2"], true)
jsgetFieldById("issuetype").setOptionsVisibility(["12345","67890"], true)
setReadOnly(readable)
Sets a field to read-only.
Parameter: readable
Parameter type: boolean
jsconst summary = getFieldById("summary").setReadOnly(true)
Hidden fields
When the text (single), select list (single and multiple), checkbox, radio and number fields are set to read only but have no value in Issue View, they will be hidden.
setRequired(required)
Updates a field as to whether or not it should be required.
Parameter: required
Parameter type: boolean
jsgetFieldById("summary").setRequired(true)
setValue(value)
Updates the field value.
Parameter: value
Parameter type: Depends on the field you’re updating
- Cascading Select:
setValue(value: {
parentId: string;
childId: string | null;
} | null)
jsgetFieldById("customfield_10054").setValue({ parentId: "1030", childId: "1031" })
Original Estimate:
setValue(value: number | null)
jsgetFieldById("timeoriginalestimate").setValue(4)
Summary:
string
jsgetFieldById("summary").setValue(<FieldValue>)
Description:
string or Atlassian Doc Format
, depending on your Jira configurationLabels:
string[]
Priority:
setValue(value: string | null)
jsconst priority = getFieldById("priority")priority.setValue("2")
Issue Type:
setValue( value: string | null) // String is the Issue Type ID
jsgetFieldById("issuetype").setValue("12345")
Assignee:
setValue(value: string | null)
jsconst assignee = getFieldById("assignee")assignee.setValue("5556634")
Reporter:
setValue(value: string | null)
jsgetFieldById("reporter").setValue("1234-3434-324234")
FixVersions:
setValue(value: string[] ) // Strings of version Ids
jsgetFieldById("fixVersions").setValue(["12345","56789"])
Components:
setValue(value: string[] ) // Strings of component Ids
jsgetFieldById("components").setValue(["12345","56789"])
Parent:
setValue(id: string | null ) // String of parent Id
jsgetFieldById("parent").setValue("10001")
Affects versions:
setValue(value: string[] ) // Strings of version ids
jsgetFieldById("versions").setValue(["10000", "10001"])
Custom single select:
setValue(value: string | null)
jsconst singleSelect = getFieldById("customfield_01231") singleSelect.setValue("3")
Custom multiple select:
setValue(value: string[])
jsconst multipleSelect = getFieldById("customfield_01232") multipleSelect.setValue(["4", "5"])
Custom user picker:
string
- user account id
jsconst singleUserPicker = getFieldById("customfield_012321") singleUserPicker.setValue("557058:db4467a5-32f3-48f9-be3b-687a1bc0468c")
Custom multiple user picker:
string[]
- users account ids
jsconst multiUserPicker = getFieldById("customfield_012322") multiUserPicker.setValue(["557058:db4467a5-32f3-48f9-be3b-687a1bc0468c", "712020:b81688df-0c5d-44cb-bc11-315f0e8e4390"])
Custom paragraph string:
// Plain-text editor: | type ADF = {version: 1, type: 'doc', content: Node[]} // Rich-text editor (ADF format)//
https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/- Custom text field:
string
Custom checkbox fields:
string[]
- checkbox option idsjsconst checkbox = getFieldById("customfield_02133").setValue(['10021','10022'])
Custom Radio Buttons Field
string
- Id of option valuejsconst radioButtons = getFieldById("customfield_02135").setValue('10021')
Custom Url Field
string
jsconst urlField = getFieldById("customfield_02134").setValue("https://www.adaptavist.com")
Custom Date Picker Field
string - Format must be yyyy-mm-dd
jsconst datePicker = getFieldById("customfield_02136").setValue('2023-11-14')
Custom Number Field
numberjsconst numberField = getFieldById("customfield_02138").setValue(100')
Status
setValue(transitionId: string )
// String of transition ID
jsgetFieldById("status").setValue("10")
Due date
string - Format must be yyyy-mm-dd
jsconst dueDate = getFieldById("duedate").setValue("2024-11-05")
Target start date
string - Format must be yyyy-mm-dd
jsconst targetStart = getFieldById("customfield_10022").setValue("2024-11-05")
- Target end date
string - Format must be yyyy-mm-dd
jsconst targetEnd = getFieldById("customfield_10023").setValue("2024-11-05")
setVisible(visible)
Updates the visibility of the field.
Parameter: visible
Parameter type: boolean
jsgetFieldById("summary").setVisible(false)
Behaviours on Screen Tabs
Demo video
You can watch our helpful demo video highlighting how the Behaviours on Screen Tabs feature works.
It is important to note that all Behaviours on screen tabs methods are only accessible on the object returned by getScreenTabById
.
jstype ScreenTab = { getId: () => string; isVisible: () => boolean; setVisible: (isVisible: boolean) => void; focus: () => void; }
getId
Returns the screen tab identifier.
Return type: string
jsgetId(): string
isVisible
Returns true
if the tab is currently visible. Returns false
otherwise.
Return type: boolean
jsisVisible(): boolean
setVisible
Changes tab visibility.
Return type: void
jssetVisible(value: boolean): ScreenTabAPI tab.setVisible(false);
Do not hide in-focus tabs
Always ensure that you are not hiding the tab currently in focus. Doing so means your UIM won't be applied and the onError
callback will receive a SCREENTABS_VALIDATION_FAILED
error.
focus
Switches the focus to a given screen tab. Automatically puts other visible tabs out of focus.
Return type: void
jsfocus(): ScreenTabAPI tab.focus();
The screen tab setter methods are grouped and applied after the completion of other Behaviours that run on load
or on change
. This means that reading the values using the getter methods will always return the screen tab’s initial state.
You can refer to Atlassian's UI Modifications documentation for more details about screen tabs.
Make REST Requests
You can use makeRequest
to hit the Jira Cloud REST API.
Parameters:
url: string of the rest endpoint
requestOptions: Optional request options of type RequestInit | typescript - v3.7.7
Return type: Promise<{status: number, body: JSON }>
For example:
jsconst res = await makeRequest("/rest/api/2/myself"); if(res.body.accountId == "the accountId") { logger.info("User is bob"); }
Some Jira REST APIs are not supported on Atlassian Forge and will, therefore, not work on the Behaviours feature. For example, requests with OAuth2 permission scopes generally work on Forge. Where this scope is absent, we expect that the API endpoint is not supported on Forge.
You can make a POST request that specifies request options and headers with the makeRequest
method. You can also make other types of REST requests, including PUT or POST. The example below shows how to make a POST request to the Jira expression API to test if an issue has more than 25 characters in the description and if so, to set some text in the summary field.
jsconst body = `{ "expression": "issue.description.plainText.length >25", "context": { "issue": { "key": "DEMO-1" // Specify the Issue key to test agains }, "project": { "key": "DEMO" // Specify the project key here for the project of the issue being tested against } } }`; const res = await makeRequest("/rest/api/3/expression/eval?expand=meta.complexity", { method: "POST", headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: body }); if(res.body.value === false){ getFieldById("summary").setValue("Description field has less than 25 characters"); }else{ getFieldById("summary").setValue("Description field has more than 25 characters"); }
Logs
A logger is available, which will allow admins to view logs on the log page. This can be accessed by using the logger object.
Using the logger allows you to read the logs from your scripts inside the ScriptRunner Logs page.
For example:
logger.info("hello world");
Available functions - each method takes a string parameter:
warn(msg)
debug(msg)
info(msg)
trace(msg)