Refresh Issue using Event Lister Scriptrunner

Hello, I need to refresh the issue without closing the window in order to update in “real time” the changes i´m using the method AP.jira.refreshIssuePage(); and this is my code:

// these 4 values will be installation dependent
def input1CfId = 'customfield_10048' // Cantidad disponible
def input2CfId = 'customfield_10034' // Costo Unitario
def outputCfId = 'customfield_10050' // Valor Total de inventario
def projectKey = "BP"

if (issue == null || issue.fields.project.key != projectKey) { 
    logger.info("Wrong Project ${issue.fields.project.key}")
    return
}

def input1 = issue.fields[input1CfId] as Double 
def input2 = issue.fields[input2CfId] as Double

if (input1 == null || input2 == null) { 
    logger.info("Calculation using ${input1} and ${input2} was not possible")
    return
}

def output = input1 * input2

AP.jira.refreshIssuePage();

if (output == (issue.fields[outputCfId] as Double)) { 
    logger.info("already been updated")
    return
}

put("/rest/api/2/issue/${issue.key}") 
    .header("Content-Type", "application/json")
    .body([
        fields:[
                (outputCfId): output
        ]
    ])
    .asString()

Scriptrunner interface give me this:
[Static type checking] - The variable [AP] is undeclared @ line 23, column 1
[Static type checking] - No such property: jira for class: java.lang.Object @ line 23, columna 3.

Could someone help me?

AP.jira.refreshIssuePage(); is Javascript code, not Groovy.
The script that you posted runs on the server, not in the browser: in that context there is no browser at all (what if you’re running a transition/updating an issue using the REST API?) so you can’t really do that.

I don’t know if Scriptrunner has a custom way to send messages to the browser, you should probably ask their team, but there is no general way to trigger a page refresh from the backend.

1 Like