Scriptrunner Behaviour script to insert data into TableGrid Next Generation

Ashok_Chakra March 25, 2022

Hi ,

I'm trying to insert the row into Table Grid  next generation (1.13.1-jre8) through behaviour script through server side script.

Following is the behaviour script:

import groovy.json.JsonBuilder
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.plugin.PluginAccessor
import com.atlassian.jira.user.ApplicationUser


def actions

def ata = getFieldByName("Park No").getValue() as String
def jta = getFieldByName("TSK").getValue() as String
Issue issue = issue


if (ata) {
def httpBuilder1 = new HTTPBuilder("http://localhost:8080/")
httpBuilder1.ignoreSSLIssues()
if(jta){
actions = httpBuilder1.request(Method.GET, ContentType.JSON) {
uri.path = "rest/scriptrunner/latest/custom/fetchdetail"
uri.query = [query:"$ata/$jta"]
//headers."User-Agent" = "My JIRA"

response.failure = { resp, reader ->
log.warn("Failed to query GitHub API: " + reader.text)
}
}

}else{
actions = httpBuilder1.request(Method.GET, ContentType.JSON) {
uri.path = "rest/scriptrunner/latest/custom/fetchdetail"
uri.query = [query:"$ata"]
//headers."User-Agent" = "My JIRA"

response.failure = { resp, reader ->
log.warn("Failed to query GitHub API: " + reader.text)
}
}

}

// get an issue
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class);
Long issueId = issue.getId()

// Get TGNG custom field id
CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class)
CustomField tgngCustomField = customFieldManager.getCustomFieldObjectsByName("Park Details").get(0)
Long tgngCustomFieldId = tgngCustomField.getIdAsLong()


ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Get GridService
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor()
Class apiServiceClass = pluginAccessor.getClassLoader().loadClass("com.idalko.tgng.jira.server.api.GridService")
def gridService = ComponentAccessor.getOSGiComponentInstanceOfType(apiServiceClass)


try {
     gridService.addRows(issueId, tgngCustomFieldId, user, [
      ["ParkDetailGrid_ParkName": "Buy groceries", "ParkDetails_Description":"Test1"],
      ["ParkDetailGrid_ParkName": "Plan vacation", "ParkDetails_Description":"Test2"] ]
)
} catch (Exception e) {

}

}

 

Getting following error:

[c.o.jira.behaviours.BehaviourManagerImpl] Found class null but could not find method run
groovy.lang.MissingPropertyException: No such property: issue for class:

 

What change should I make so that Behaviour script can be executed on value change in TSK or ParkNo field

2 answers

0 votes
Ksenia Abdulina March 1, 2024

Hi @Ashok_Chakra

Any updates on your request? 

I have similar question.. maybe Table Grid Next Generation just can't work with Behaviors?? 

0 votes
Ashok_Chakra March 28, 2022

Since this case is not created hence there issue object is null and there is current ID created. that's why row insert is failing. if we use old case id then it is updating the old case or pre-exist case. my requirement to add row in current issue table grid. Can some one help on this.

Rolf Lader
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 10, 2022

@Ashok_Chakradid you find a solution for your problem?

Suggest an answer

Log in or Sign up to answer