You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi,
Here below is the api Json response to search the project where the Kickoff date is today selection
{
"status": "OK",
"data": [
{
"projectName": "iEvalAuto_47119",
"bhuIds": "bhu_04454(FY19)",
"handOver": null,
"createdDate": "2019-03-20 08:43:12.0",
"modifiedDate": "2023-04-14 06:54:23",
"projectDates": {
"Kick-Off_startDate": "2023-03-31",
"Mobilization_startDate": "2023-03-30",
"Mobilization_endDate": "2023-04-22",
"Design_startDate": null,
"Design_endDate": null,
"Development_startDate": null,
"Development_endDate": null,
"IT_startDate": null,
"IT_endDate": null,
"PT_startDate": null,
"PT_endDate": null,
"UAT_startDate": null,
"UAT_endDate": null,
"RT_startDate": null,
"RT_endDate": null,
"Production Cut Over_startDate": null,
"Production Go Live_startDate": null,
"Warranty_startDate": null,
"Warranty_endDate": null,
"Create CR By_startDate": null,
"Have Final Eval By_startDate": null,
"KT_startDate": null,
"KT_endDate": "2023-04-30"
}
}
]
}
So, Required to help on groovy script to compare each field of json response on the above with each field of jira customfield of the project. if both values are different. then update the customfield in jira project. (Note: if values are similar no need to update)
Please help to solve the issue.
Thanks & Regards
Himabindu.P
Welcome to community! This should get you started but I haven't tested it so I would recommend doing it in stage and building in additional functions and verifying it works before putting it in your environment. I can not be responsible for anything that doesn't work properly.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
// Define the custom field mappings
def customFieldMappings = [
"Kick-Off_startDate" : "customfield_10000",
"Mobilization_startDate" : "customfield_10001",
"Mobilization_endDate" : "customfield_10002",
// Add the rest of the custom field mappings here
]
// The JSON response from the API
def jsonResponse = '''
{
"status": "OK",
"data": [
{
// The rest of the JSON data
}
]
}
'''
// Parse the JSON response
def jsonSlurper = new groovy.json.JsonSlurper()
def jsonData = jsonSlurper.parseText(jsonResponse)
def projectDates = jsonData.data[0].projectDates
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueByCurrentKey("PROJECT-KEY") // Replace "PROJECT-KEY" with the relevant project key
if (issue) {
customFieldMappings.each { jsonKey, customFieldId ->
def customField = customFieldManager.getCustomFieldObject(customFieldId)
def apiValue = projectDates[jsonKey]
def jiraValue = issue.getCustomFieldValue(customField)
if (jiraValue?.toString() != apiValue) {
def changeHolder = new DefaultIssueChangeHolder()
customField.updateValue(null, issue, new ModifiedValue(jiraValue, apiValue), changeHolder)
}
}
// Reindex the issue after updating custom fields
issueManager.reindex(issue)
} else {
println("Issue not found")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.