ScriptRunner - Last comment is not displayed

Oleksii Zhelaha April 11, 2024

Hi, 

I'm using the Scripted Fields in ScriptRunner to display the last comment of the issue. 
Even though the script runs successfully, it displays it as empty in the filter, has anyone encountered this?

image.pngimage.png

2 answers

1 accepted

4 votes
Answer accepted
Sean Chua _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 11, 2024

Hey @Oleksii Zhelaha ,

For for Scripted Fields (SF) on Cloud, it works as an "On Load" update at this point of time. You need to open the issue and let it update - then you should be able to see the last comment field get populated.

image.png

For whatever reason you need to regularly update the SF with data because tickets are not viewed - it is technically possible to run a Scheduled Job to update the SF fields with the required data but there are limitations (there could be more as well depending on what you want to do exactly....)

If you are interested in doing that, then you probably can use a sample like:

//your query
def jqlQuery = 'assignee = currentUser() AND resolution = Unresolved order by updated DESC'

// Fetch issues based on the JQL query
def searchResult = get("/rest/api/3/search")
    .queryString("jql", jqlQuery)
    .queryString("maxResults", 50) // Adjust the maxResults to your needs
    .queryString("fields", "comment") //fetch the comment field or whatever
    .asObject(Map).body

//whatever you wanna do for your searchResults goes after this for checking, updating etc etc
//just a random sample , I didn't close it..
searchResult.issues.each { issue ->
def issueKey = issue.key

// Fetch issue data including changelog blah blah blah
def response = get("/rest/api/3/issue/${issueKey}?expand=changelog")....

 
Feel free to Get Help from us at Adaptavist/ScriptRunner, or if you want to get a feature demo etc - feel free to book time with us ScriptRunner CSM .

Hope it helps,
Sean

 

Oleksii Zhelaha April 11, 2024

well, I added a new comment to the issue, but it does not appear. what is the point of creating a built-in scripted field if you need to use an additional script to use it? not sure if the problem is this.

Oleksii Zhelaha April 11, 2024

I do not see anything about additional scripts in this doc:
https://docs.adaptavist.com/sr4jc/latest/features/scripted-fields/example-scripted-fields

Sean Chua _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 11, 2024

Use Scripted Fields like Jira Custom Field was just updated early March 2024. At the moment, it is a known limitation that the scripted field recalculates only upon issue load. We are working to improve this however there is currently no time frame as to when this will be released.

The sample i've shared is IF you would like to use a Scheduled Job to regularly update the field without going into the ticket individually which is a potential workaround so that you can see the details in the places you want like the filters, or dashboard:

image.png

Oleksii Zhelaha April 12, 2024

ok, thanks man, I got it.
basically, I need to add a comment and then reload the page.
but looks like I found the issue in my case. I didn’t add this field to the screen.

Like Sean Chua _Adaptavist_ likes this
Oleksii Zhelaha April 12, 2024

@Sean Chua _Adaptavist_ , could you advise how to use Scheduled Job for this instant update? ;) 
Run one of the scripts above every hour or something? I have a very large amount of filters on my dashboard where I need to see the last comment immediately. We are working as a support team and checking the comments from our customers is important for us.

Oleksii Zhelaha April 15, 2024
Sean Chua _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 18, 2024

Hey @Oleksii Zhelaha , apologies for the late response. I was off for a few days and caught up with stuff etc.

I don't have a sample for updating the comment itself but you can likely have a logic to;

For the query, you can use something like what I shared above, if there are many tickets which needs to be updated - you could hit some limitations there. So I would recommend you to open a Support Ticket with our ScriptRunner support engineers to see if they can investigate with you to meet your needs within their Support SLA .

Regards,
Sean

0 votes
Matt Parks
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 11, 2024

What happens if you take that filter, add it to a gadget on a dashboard, and then display that field on your gadget?

MattD
Contributor
April 11, 2024

Also, some comments may not be visible to all users

Oleksii Zhelaha April 11, 2024

the same. I do not see any comments

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events