Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

How to add current user name and date(with time) to read only text field in jira cloud?

Hello Team,

I have a select list(single choice) custom field and once I enter the value in, I need to add the name of the user who updated the field along with the time updated?

I am working on JIRA cloud and wanted know if in any way it is possible or not?

Thanks and regards,

Danish Hussain Sabunwala

2 answers

1 accepted

2 votes
Answer accepted

Hi @Danish Hussain Sabunwala 

You can achieve this using an automation rule. The trigger would be when the field value is changed for your single-select list.

Your action would be the Edit Issues action, where you would select the text field in which you want to add in the details. If you used a smart value of {{initiator.displayName}}, {{now.jqlDateTime}}, then this would fill the field with User's display name, 2021-06-02 15:15.

This will work if the text field is on the view screen but not on the edit screen, so will remain a read-only field

Hello @Callum Carlile _Automation Consultants_ ,
Thanks a lot for the response.

Maybe my question confused you, sorry for that. 

I get that the following, if applied, would only update these values one's and if I try to update it a second time, my first values will be lost.

Example: My single-select list contains : A1 and A2 values. If I select A1 the read-only text field should have "User's display name, 2021-06-02 15:15: now If another user comes and selects A2; Then the read-only text field should have

"User's display name, 2021-06-02 15:15:

Another User's display name, 2021-06-02 16:16:.

Is there any workaround for this?

Thanks and regards,

Danish Hussain 

Hi @Danish Hussain Sabunwala  Yeah this is possible :) if you use the smart value of:

{{issue.name_of_text_field}} : {{initiator.displayName}}, {{now.jqlDateTime}}

The first smart value here just uses whatever's currently in the field, then adds the name and date/time of the initiator to it.

So if a user edits the single-select list the first time:

Name1, date1/time1

...then another user changes this field value

Name1, date1/time1 : Name2, date2/time2

And so on...

You can of course edit the smart value to use any sort of commas, colons or whatever you like to separate the values, I have just used these as an example, the important part is the stuff within the curly brackets

Hello @Callum Carlile _Automation Consultants_ ,  this is exactly what I was looking for.

Thanks and Regards,

Danish Hussain

This information is actually in the issue's history. Anyway, you can achieve this using ScriptRunner's Script Listeners.

To do that:

1. Navigate ScriptRunner > Script Listeners > Add Listener > make appropriate configurations

2. Under "On these events", choose "Issue Updated" or any events suitable for your use case.

3. Under "Code to run", paste in following snippet:

def result = get("/rest/api/2/issue/${issue.key}/changelog")
.header('Content-Type', 'application/json')
.asObject(Map)

def changes = result.body.values.findAll({
it.items.field == ["Change type"] //Replace with your field name
})

if (!changes.isEmpty()) {
def lastUpdatedBy = changes.last().author.displayName as String
def lastUpdatedTime = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSSZ", changes.last().created).format("yy-MM-dd HH:mm", TimeZone.getTimeZone("Asia/Kuala_Lumpur"))

// get custom fields
def lastUpdatedByCf = get("/rest/api/2/field")
.asObject(List)
.body
.find {(it as Map).name == 'Last Updated'} as Map //Replace with your read-only text field name

def resp = put("/rest/api/2/issue/${issue.key}")
.header('Content-Type', 'application/json')
.body([
fields: [
(lastUpdatedByCf.id): lastUpdatedBy + ", " + lastUpdatedTime,
]
])
.asString()
}

4. You need to manually set the time zone because you are displaying string and Jira will not adjust automatically to the user's time zone and will always display time in UTC. To check all available time zones., you can run following snippet in ScriptRunner > Script Console:

TimeZone.getAvailableIDs()

 

An alternative would be implement this using Scripted Fields. The script should be similar.

An update to the script, which is more efficient:

def hasFieldChanged = changelog.items.any { it.field == "Change type" } //Replace with your monitoring field name

if (hasFieldChanged) {
def fullChangelog = get("/rest/api/2/issue/${issue.key}/changelog")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
.values
.last()

def lastUpdatedBy = fullChangelog.author.displayName as String
def lastUpdatedTime = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSSZ", fullChangelog.created).format("yy-MM-dd HH:mm", TimeZone.getTimeZone("Asia/Kuala_Lumpur"))

def lastUpdatedByCf = get("/rest/api/2/field")
.asObject(List)
.body
.find {(it as Map).name == 'Last Updated'} as Map //Replace with your read-only text field name

def resp = put("/rest/api/2/issue/${issue.key}")
.header('Content-Type', 'application/json')
.body([
fields: [
(lastUpdatedByCf.id): lastUpdatedBy + ", " + lastUpdatedTime,
]
])
.asString()
}  

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