Skip to end of banner
Go to start of banner

Custom Fields Aliases

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

 Aliases represents a powerful mechanism to indirectly refer custom fields, making your scripts intention obvious. 


The Case For Aliases

 

Addressing fields by its Jira internal name is not really nice. Nobody likes to write 'customfield_12067' instead of a meaningful variable name. This is why we allow addressing the fields by name, with the disadvantage that this may prove erroneous (field name resolution does not take into account that there are maybe more than one custom field with that name).

Consider the following code:

if(isNotNull(customfield_10001) // or #{The Reported User)} if accessed by name
{
  assignee=customfield_10001; // assign the report to him or her
}

 

 

In absence of comments, this code meaning is elusive, the whole purpose of the script evades from the sight of the programmer. A better variant is:

if(isNotNull(#{Reported User}) // or customfield_10001 if accessed by number
{
  assignee=#{Reported User}; // assign the report to him or her
}

 

As we mentioned, this style of coding has the disadvantage that there may be more than one custom field named "Reported User", in which case SIL takes into account the first custom field resolved by name. This may not prove exactly what you want and may lead to confusion, incorrect results and last but not least, frustration. We want to avoid frustration at any cost. Plus, we do not like very much the syntax #{custom field name containing spaces} - even if it was requested by our users -, since we consider it is cluttering the code.

 

Therefore, SIL has created its own custom field naming system, one that is independent of the IDs attributed by JIRA to custom fields and one which can provide the much needed uniqueness of the custom fields names. The feature is called SIL aliases, and allows you to alias any custom field with a friendly name. Let's see how this simple example looks with aliases.

 

Aliases

 

Creating aliases is a simple task of editing a properties file named 'sil.aliases', which need to be found in Kepler Home directory (usually 'kepler'). This file must contain pairs in the form alias=customfield_id. For our example above, we should edit it and put an entry like:

sil.aliases
# custom fields aliases
reportedUser=customfield_10001

 

The script may be re-written such, instead of the custom field id or name, we use the alias:

 

 

if(isNotNull(reportedUser)) {
  assignee=reportedUser;
}

 

 

 

Now, the code looks clean, and the intention of the script creator is clear, even without comments.

 

Consequences

 

Using SIL aliases instead of custom fields ids and names is paramount. There are important consequences when maintaining a complex JIRA install:

  1. When and if a custom field gets deleted and recreated, its id will change. Using SIL aliases allows you to keep your code unchanged, you just need to point in the sil.aliases file the new custom field id for that alias.
  2. May simplify the syntax and may clarify the meaning of the scripts
  3. Aliases provide independence of the JIRA instance.

 

If 1 & 2 are obvious, let's discuss a bit about the 3rd point: the independence of the JIRA instance.  Think of two JIRA systems, say test environment and production environment. You do not want to work directly into production (that would be a very bad thing to do, don't do this at home) so normally you develop your new workflow on the test machine and you add a new custom field, because the business needs it. Now, everything is ready and you want to publish changes into production system, so:

  • You create on the production system a custom field with the same name (but JIRA assigns its own id, which may be different from the id from the test system)
  • You move over the SIL scripts
  • You import the workflow, with the paths changed to the above SIl scripts (if necessary)

 

Now, if you referred your custom field by its id, you need to go through every script and do a search & replace with the new id. If you referred it by name, maybe your colleague just added a custom field, used in some other project, that has the same name.

However, if you used the alias, you just place your alias in that file, and everybody will be happy.

 

It is important to keep aliases names unique. If more than one alias with the same name exists, the last one is taken into consideration, the rest are discarded.

 

Another Example

If you're still not convinced, let's take a look at another example. Consider this postfunction:

 

 

test.sil
 if(customfield_10000 < currentDate() && customfield_10001 > currentDate()) {
	assignee = customfield_10002;
 }

 

 

From the code above, it is quite clear that customfield_10000 and customfield_10001 are dates; customfield_10002 is a user picker. But their meaning is obscure. However, if we define the following aliases:

 

sil.aliases
 initialDate=customfield_10000
 finalDate=customfield_10001
 contact=customfield_10002

 ... then we use them in our SIL program ...

test.sil
 if(initialDate < currentDate() && finalDate > currentDate()) {
 	assignee = contact;
 }

...something starts to make sense, don't you think?

 

 

  • No labels