Script Runner Behaviours - Examples

Examples for working with the Message Field application using ScriptRunner Behaviours are collected below. Each example shows the full file - copy it as is.

File: Hide message.groovy

def field = getFieldById("customfield_10000")
field.setHidden(true)

File: Set message as JSON.groovy

/*
messageType values: success, info, warning, error, change (Type "Change" works only for "Show as flag - No" and Jira 8.4.0+), SIMPLE_VIEW

viewVersion: v1 (standard), v2 (big)

{
  "title": "Test title",
  "body": "test body",
  "messageType": "info",
  "asFlag": true,
  "viewVersion": "v1"
}
*/
def field = getFieldById("customfield_10000")
field.setFormValue("{\"title\":\"Test title\", \"body\":\"Test body\", \"messageType\":\"success\"}")

File: Update message as JSON from Map for Jira Service Desk.groovy

import groovy.json.JsonOutput

def field = getFieldById("customfield_10109")
def message = [:]
message << [messageType: "warning"]
message << [title: "Test title2"]
message << [body: "<a>Test body2</a>"]
message << [asFlag: false]
message << [jibrokMessageKey: true]//Require for Service Desk (JSM) until v4.14.* of Message field version

field.setFormValue(JsonOutput.toJson(message))

File: Update message as JSON from Map.groovy

import groovy.json.JsonOutput

def field = getFieldById("customfield_10000")
def message = [:]
message << [messageType: "warning"]
message << [title: "Test title2"]
message << [body: "<a>Test body2</a>"]

field.setFormValue(JsonOutput.toJson(message))

File: Update message only body.groovy

def field = getFieldById("customfield_10000")
field.setFormValue("""
MESSAGE1 <b>test</b><br>
MESSAGE2 <b>test</b>
""")