Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using Rest Endpoint to update a bundle field but on Customer Portal (Refined) shows json like values

Michael H December 10, 2024

I'm using Databricks to send over data to Jira via Rest Endpoint to update a Bundle Field (specifically date values) in Jira and it works successfully and shows the changes on Jira. However for our users, we have them interacting with Jira through Refined and on our portal the values end up showing in a Json esque format. 

I'm trying to figure out how to make the bundle field display correctly and determine what's the cause of the problem and why it only occurs on the Refined website.

 

 

This is how the data ends up looking instead of showing user readable values

 

{"configurationId":13,"baseGroupId":{"fields":[{"id":"871cc638-84eb-480b-b864-498a7377e900","originId":"871cc638-84eb-480b-b864-498a7377e900","value":"test 0"},{"id":"b8c0706d-e836-459f-a757-3db2c3b8708c","originId":"b8c0706d-e836-459f-a757-3db2c3b8708c","value":"2023-08-21"},{"id":"4625494a-202e-468f-8f8b-344048b2935b","originId":"4625494a-202e-468f-8f8b-344048b2935b","value":"2023-12-31"}],"order":0},"8b288c63-486a-428f-b089-ce6d3774cb60":{"fields":[{"id":"a84ab6c9-0c34-436f-8f9d-dda3d82c4a72","originId":"871cc638-84eb-480b-b864-498a7377e900","value":"testing 1"},{"id":"ab50de91-c200-4754-b694-f0c526b3728f","originId":"b8c0706d-e836-459f-a757-3db2c3b8708c","value":"2024-01-01"},{"id":"29a06228-4889-4db4-bed0-9d85c5303949","originId":"4625494a-202e-468f-8f8b-344048b2935b","value":"2024-03-31"}],"order":1},"1180bed3-48ef-4d9d-ad85-f193ef240cab":{"fields":[{"id":"b0385981-a549-4ab0-96b2-1aec2dfc946c","originId":"871cc638-84eb-480b-b864-498a7377e900","value":"testing 2"},{"id":"4ba71a43-f16a-4bf7-a1c6-6a634344f6f4","originId":"b8c0706d-e836-459f-a757-3db2c3b8708c","value":"2024-02-01"},{"id":"8ab83966-5679-4cab-8c94-b87df92865ea","originId":"4625494a-202e-468f-8f8b-344048b2935b","value":"2024-09-30"}],"order":2}}

2 answers

0 votes
Raj Sehmi
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.
December 13, 2024

Hi Michael,

Interesting issue!

If you haven't already done this - could you submit a support ticket over at help.refined.com, for our support folks to dig deeper into this? 

Best regards, Raj from Refined

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
December 10, 2024

Hi @Michael H

Please share the code you are currently using for your REST Endpoint so I can review it and provide some feedback.

Thank you and Kind regards,
Ram

Michael H December 11, 2024
Thank you for the reach out, I have provided the code used in both databricks and Jira. Looking forward to your response. Do note i did change some items as not provide too much personal info. Sorry if the formatting is messy not sure if the code block worked, it didn't seem to let me copy and paste code into it.
 
Databricks code
import requests
custom_field_id = "customfield_13516"

test_upload = {'TEST-100': [{'updated': '2024-12-08', 'fiscal_quarter_end': '2024-12-29', 'index': 0},
                            {'updated': '2024-12-26', 'fiscal_quarter_end': '2024-12-30', 'index': 1}]}



# Set the authentication token
token = secret_token
# Set the request headers with the token
headers = {
    "Authorization": f"Bearer {token}",
    "Content-Type": "application/json"
}

# Prepare the payload to update the custom field options
#change context value depending on what customfield we are using
payload = {
    "field": custom_field_id,
    "options": test_upload,
}

# Send the POST request to update the custom field options
#json.dumps converts python object dictionary esque data from python into json format
if dev_level == "prod":
  response = requests.post(api_url, data=json.dumps(payload), headers=headers)

# Check the response status
if response.status_code == 200:
  print(f"Custom field options updated successfully for field ID {custom_field_id}. Response:", response.text)
else:
  print(f"Failed to update custom field options for field ID {custom_field_id}. Response:", response.text)

 

Jira Rest Endpoint Code

import java.lang.Integer
import java.util.Dictionary
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import groovy.json.JsonSlurper
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.intenso.jira.plugins.bundledfields.api.ExtensionBundledService
import com.deviniti.plugins.bundledfields.api.issue.BundledField
import com.deviniti.plugins.bundledfields.api.issue.Subfield
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate
@WithPlugin("com.intenso.jira.plugins.jsd-extender")
@PluginModule
ExtensionBundledService extensionBundledService
restEndPointFunc(httpMethod: "POST", groups: ["group1", "group2"] ) { MultivaluedMap queryParams, String body ->
    def data = new groovy.json.JsonSlurper().parseText(body)
    // data['options'] is a list of {issuekey : [startdate, enddate]} key value dictionaries
    def dict = data['options']
    def bundledFieldId = data['field'].toString()
    def pattern = "yyyy-MM-dd"

    // grabbing all issue keys in the dictionary
    def test = (dict.keySet() as List)
   
    // converting the list of issues into a string with each issue separated by a comma in said string
    def test2 = test.collect{ "\"${it}\"" }.join(',')
    log.warn(test2)
    // defining jqlquery with said issuekeys
    def jqlquery = "issuetype = 'TEST' AND issue in (${test2}) ORDER BY key"
    log.warn(jqlquery)
    Issues.search(jqlquery).each { issue ->
        log.warn(issue)
        BundledField bundledField = extensionBundledService.getBundledFieldDraft(issue, bundledFieldId)

        // need to convert issue from DocumentIssueImpl[issueKey=...] type to string
        log.warn(issue.getKey())
        String issueKey = issue.getKey()

        // 0th index contains start date info, 1st index contains end date info, and 2nd index is subfield group number
        for(value in dict[issueKey]){
            def startDate = value['updated']
            def endDate = value['fiscal_quarter_end']
            def groupNumber = value['index']

            log.warn(startDate)
            log.warn(endDate)
            log.warn(groupNumber)
           
            startDate = Date.parse(pattern, startDate as String)
            endDate = Date.parse(pattern, endDate as String)

            // set the subfield values for start and end date
            bundledField.setSubfieldValue("Start Date", startDate, groupNumber as Integer)
            bundledField.setSubfieldValue("End Date", endDate, groupNumber as Integer)

        }

        bundledField.save()
    }

    return Response.ok(new JsonBuilder(['Success' : 'Success']).toString()).build()
}

Suggest an answer

Log in or Sign up to answer