It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Change create date and other system fields with Python

Hi, 

I'm trying to migrate issues from another tool to jira, I can obtain the Json and I'm creating the issues with the python method. But I cannot modify field such as 'Status', 'Created Date', 'Update date' and so on, any ideas?

1 answer

0 votes
Andy Heinzer Atlassian Team Oct 22, 2019

Hi Daniel,

I understand that you are either creating or updating Jira issues using python in some method, but I am unclear as to exactly how you are doing that.

The status field in Jira is a system field.  It is not something that you can typically change just by editing an issues in Jira. Instead you have to execute a transition in Jira in order to be able to change the status field.  It's the execution of that transition that does this.  If you're python method is calling the REST API endpoints to edit/create issues, I'd be curious to know exactly which endpoint you are accessing, and what your json payload looks like.  We do have a reference guide on which endpoints are available in https://developer.atlassian.com/cloud/jira/platform/rest/v3/

As for Created date and Update date, these too are system fields.  They are not typically expected to let end users change their values for an issue once created.  The create date is set to when the issue is created, just as the updated date is always reflecting the last update made to that issue.  End users in Jira are not expected to be able to manipulate these values.  That said, if you are a Jira administrator, you could have access to the External System import.  This importer does have the ability to change these kinds of system fields as an admin that normal end users would not have the ability to change themselves.  Perhaps you could use this method if you need to set those fields when importing issues into Jira.

I hope this helps, please let me know if you have any additional concerns about these steps.

Andy

Never-mind, I already understand the way I can build the JSON files with Pyhton. Thanks for your answer.

@Daniel Alonso Can I ask how you were able to modify the status field? I am creating a new issue in python that I would like to set the status to 'closed' immediately. Thanks

Hi Archie,

I figured out that I need to build the entire JSON Object on python.

This is how I did it:

MILESTONES are another Issue Type because we were creating Portfolio Issue types...

map_status is a function that translates the Source app statuses to Jira statuses.

def create_milestones(ch_milestones):
milestones_file=open('json_jira/milestones_to_jira.json', 'w+')
json_dict = {}
json_project = {}
project_data = []
milestones_data = []

for milestone in ch_milestones:
json_milestone = {}

id = milestone['id']
name = milestone['name']
description= milestone['description']
created = milestone['created_at']
#Map statuses
status = map_status(milestone['state'])
#Build Output
json_milestone["summary"] = name
json_milestone["description"] = description
json_milestone["externalId"] = id
json_milestone["created"] = created
json_milestone["reporter"] = "5a02285487c3eb1913c44a80"
json_milestone["status"] = status
json_milestone["issueType"] = "Milestones"
json_milestone["customFieldValues"] = [{"fieldName": "external_id","fieldType": "com.atlassian.jira.plugin.system.customfieldtypes:float","value": id}]
json_milestone["labels"] = ['ch_milestone']

milestones_data.append(json_milestone)
#Save the complete Json on a file to import to Jira
json_project["name"] = "Test Project"
json_project["key"] = "DEV"
json_project["issues"] = milestones_data
project_data.append(json_project)

json_dict["projects"] = project_data
json.dump(json_dict, milestones_file)
milestones_file.close()

As you can see, first create the dictionary, then the data inside each object data.

At the end you will see the JSON object like:

 Annotation 2020-07-01 104548.png

Once the JSON object is built you can use the External System Import to push your data in Jira.

If you have any questions please let me know.

Daniel

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you