Forums

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

In Jira Data Center asset management, set the default value to a text attribute type

VVC
Contributor
July 11, 2025

How to automatically set the text attribute type to a default value "2025" or most preferably a dynamic value of the current year at the time of object creation in Jira Data Center asset management?

I have an asset automation that concatenates three attributes and updates the object after creation. One of the attribute includes "ReportYear" of type text and it should default to current year each time. Please suggest a resolution if this is feasible to achieve in asset management automation.

 

3 answers

1 accepted

2 votes
Answer accepted
VVC
Contributor
July 17, 2025

Here is the working script that sets the text attribute value to current year after the creation of new object.

import com.atlassian.jira.component.ComponentAccessor
import java.util.Calendar
import java.time.Year

// Access the necessary components
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(
ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade")
)
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(
ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade")
)
def objectAttributeBeanFactory = ComponentAccessor.getOSGiComponentInstanceOfType(
ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.services.model.factory.ObjectAttributeBeanFactory")
)

// Get the current year
def currentYear = Year.now().toString() //Calendar.getInstance().get(Calendar.YEAR).toString()
log.warn("Current year: " + currentYear)

// Use the 'object' variable from the automation context
def objectBean = object
def attributeId = 2833 // Replace with your attribute ID
def objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(attributeId)

// Create a new attribute bean with the current year
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(objectBean, objectTypeAttributeBean, currentYear)

// Load the existing attribute bean
def objectAttributeBean = objectFacade.loadObjectAttributeBean(objectBean.getId(), objectTypeAttributeBean.getId())
if (objectAttributeBean != null) {
// Reuse the old ID for the new attribute
newObjectAttributeBean.setId(objectAttributeBean.getId())
}

// Store the updated attribute
try {
objectFacade.storeObjectAttributeBean(newObjectAttributeBean)
} catch (Exception e) {
log.warn("Could not update object attribute due to exception: " + e.getMessage())
}

2 votes
Hari Krishna
Contributor
July 11, 2025

Hi,

If you're using Jira Data Center and working with Assets, and you want to automatically fill a text field like "ReportYear" with the current year when an object is created, there’s a simple way to do it using asset automation.

Just follow these steps:

 

Go to your Assets schema and open the Automation tab

 

Create a new rule with trigger as Object Created

 

Add a condition if needed (like only for a certain object type)

 

Add an action → Edit Object

 

In the edit action, pick the "ReportYear" attribute and set the value like this:

 

{{now.format("yyyy")}}

 

That smart value will always give the current year — so if someone creates an object in 2025, it sets "2025", in 2026, it'll be "2026" — fully dynamic.

 

Just make sure the ReportYear field is left blank during creation (don’t make it required), so that automation can fill it in right after the object is created.

 

That’s all. Once set, the rule will handle it on its own without any manual input.

Stefan Stadler
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.
July 11, 2025

perfect answer. If it needs to be more complex, you could also run Groovy scripts on certain events. The triggers are the same, just the action needs to be "Execute Groovy Script" and setting up the script is a little complex.

See here for details, also on Hari's answer:

Configuring Assets automation rules | Atlassian Support | Atlassian Documentation

Like # people like this
VVC
Contributor
July 11, 2025

Hi @Hari Krishna and @Stefan Stadler I do not see Edit Object action in the automations under Object Schema configuration  in Jira Data Center on-prem 9.12.x release. Do you see this option in your instance?2025-07-11_13-51-26.jpg

 Also, I have already tried the following automation options but it still could not setup the default value for the text attribute.

 

Groovy script asset automation #1
def object = event.object
if (object.objectType.name == "Cognos") {
    object.setAttribute("ReportYear", "2025")
    object.store()
}
Groovy script asset automation #2 - 
return String.valueOf(java.time.Year.now().getValue())

Automation #3-
Action = Attribute Value
Attribute Name = ReportYear
Value = 2025

Like John Funk likes this
Stefan Stadler
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.
July 11, 2025

Attribute value is the selection you have to take.

Select "Attribute value", specify "ReportYear" as the attribute name and use the smart value in the value section.

Like John Funk likes this
VVC
Contributor
July 11, 2025

Unfortunately, this is still NOT working, as the Report Year attribute is empty before and after the object creation.

2025-07-11_14-11-15.jpg

Like John Funk likes this
Stefan Stadler
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.
July 11, 2025

Hi @VVC 

what happens if you explicitly set 2025 as value? And what is the data Type of the attribute?

Hari Krishna
Contributor
July 11, 2025

Hi,

Yes, that's correct — in Jira Data Center 9.12.x, the "Edit Object" action isn’t available in Assets Automation yet. To dynamically set the "ReportYear" field (Text type) during object creation, you can use the "Execute Groovy Script" action instead.

Here’s a working script that sets the current year:

import java.time.Year

def object = event.getObject()
if (object.objectType.name == "Cognos") {
def currentYear = Year.now().toString()
def attrBean = objectType.getObjectTypeAttributeBean("ReportYear")
object.setAttribute(attrBean.getId(), currentYear)
object.store()
}

Make sure:
- "ReportYear" is of type Text
- It’s not marked as required (so the automation can populate it)
- You use this script in an "Object Created" trigger

Tested on 9.12.1 and it worked well. Let me know if it helps!

Like Stefan Stadler likes this
VVC
Contributor
July 14, 2025

Thanks @Hari Krishna . I'm sorry to inform that this script is still not working for me and our Jira version is 9.12.6. The ReportYear is optional and a Text type attribute. After the Object is created, the Report Year is still seen blank. I wonder if this is a known issue of Jira asset automation, so I will raise a support ticket for further assistance and keep you posted.

VVC
Contributor
July 14, 2025

@Stefan Stadler If I set the value of ReportYear text attribute to 2025 then the other automation which concatenates 3 attributes Name, ReportYear and DepartmentCode works just fine. When trying to set the ReportYear through your Groovy Script or other reference groovy script Automation then ReportYear is left blank.

Hari Krishna
Contributor
July 15, 2025

Hi @VVC ,

Thanks for the update. It looks like the script is getting triggered, but the value is not being saved into the ReportYear attribute.

Try updating the script slightly to fetch the attribute differently. Instead of using getObjectTypeAttributeBean, use this:


import java.time.Year

def object = event.getObject()
def currentYear = Year.now().toString()

def reportYearAttr = object.objectType.attributes.find { it.name == "ReportYear" }
if (reportYearAttr) {
object.setAttribute(reportYearAttr.id, currentYear)
object.store()
}

Also, make sure no other automation is conflicting with this one. If another rule is trying to update the same attribute or object at the same time, it might overwrite this value.

If this still doesn't work, it's possible that the attribute value isn't persisting due to a bug or limitation in the version you're using. Raising a support ticket is a good next step.

Let me know if you'd like help testing this further.

Stefan Stadler
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.
July 16, 2025

I would also add some kind of logging so that you are aware, where the function is failing and what is actually executed. For example, I would add a logging statement to print out the reportYearAttr and also print a statement before and after the store function being called.

Like Hari Krishna likes this
VVC
Contributor
July 16, 2025

Here is the issue with the script from the Asset Script Console

2025-07-16_12-14-22.jpg

VVC
Contributor
July 16, 2025

On a side note, would it be possible to concatenate the ObjectID, ReportYear and ObjectName using Groovy scripting for Jira asset management in Data center?

0 votes
Stefan Stadler
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.
July 16, 2025

Hi @VVC 

I am adding this as a new answer to make it better visible to the community.

The problem is, that event is not really existing in the context of Asset scripting.

In the past, I was able to run the following, so I adjusted the above example (always checking, if the object really is existing, of course):

import java.time.Year

import com.riadalabs.jira.plugins.insight.services.automation.log.AutomationLogger

def log = AutomationLogger.getInstance()

def object = binding.variables['object']

def currentYear = Year.now().toString()

if(object){

log.info("Found object, starting to process: ID: ${object.id}  Label: ${object.label}")

def reportYearAttr = object.objectType.attributes.find { it.name == "ReportYear" }

log.info("ReportYear has been found as an attribute: ${reportYearAttr}")

if (reportYearAttr) {

object.setAttribute(reportYearAttr.id, currentYear)

log.info("ReportYear shall be set to: ${currentYear}")

object.store()

log.info("ReportYear has been set")

}

}

else{

log.info("no object has been found, cancelling")

}

You can also see in the first logging statement, that the object ID and its label is also used, so you can of course use it to combine some more information in the script.

Hope this helps!

Regards,

Stefan

 

VVC
Contributor
July 17, 2025

Sorry @Stefan Stadler that didn't work either.

VVC
Contributor
July 17, 2025

As the ReportYear is now displaying 2025, I'm working on the automation to display as Concatenated string in the object name (ObjectID-ReportYear-ObjectName).

Suggest an answer

Log in or Sign up to answer