Is there a way to get a customfield id in Service Desk?

I've written a custom field for Jira, and it uses some DOM manipulation to init the field as an AUI Select2 ( I would like to use this field in Service Desk, and it seems that the "JIRA" context unfortunately doesn't exist in Service Desk (I get `Uncaught ReferenceError: JIRA is not defined` when loading the js resources). 

Ok, not a huge deal, I don't really need the JIRA object, but I was wondering if there a way to programmatically detect my custom field id so I can do the necessary DOM manipulation to get feature parity as in Jira.

1 answer

You can still use AJS in your plugin to manipulate the Service Desk fields, and any AUI objects (like select2).

BUT Service Desk is for unknown reasons different that every other atlassian product in how you access AJS.

The trick is to NOT declare AJS as a dependency, but include any non-core AUI dependencies (i dont think select2 is core yet)

<!-- Service desk you jerk. Can't have AUi/AJS ->
    <web-resource name="Banner Web Resources (for Service Desk)" key="banner-resources-jsd">
.... any of your own js/css/images

<!-- context used by all JSD pages -->

And then use some JS to wait for the delayed loading of AJS in service desk portals

// JSD errors if you declare AJS dependency, but it is available, but may load after our code
var ajsAttempt=0;
function onFunctionAvailable() {
    if(ajsAttempt++ > 50){
        console.log("AJS is not available. Statuspage integration will not load.");
        console.log("AJS Methods Ready");

        //call function to manipulate dom here... i.e. 

     console.log("AJS Methods not ready");
     setTimeout(function () {
             }, 50);

Hey, thanks for the quick reply! Do you know if there's a way to programmatically get the id of the custom field? The issue that's stumping me is in Jira my field element loads with an id that I set, but in Service Desk the id is just "customfield_15006".

Since I'm planning on deploying this across multiple instances, I can't hard-code in the id, so I was looking for ways to abstractly detect it.


yes, you'll need to use a backend JIRA service for that translation.  There is a few methods to translate the pretty name from the system ID.

So you may want to query the customfield_15006 (or approproate ID) in the backend first, and pass that ID to your front end JS.

Alternately you could use the REST api from your JS to look it up.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,227 views 5 10
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you