Auto create customfield

Originally asked by Stephen Atkinson on 08 September 2020 (original question)


Reading the source of CustomFieldSync.groovy you define a number of Closurers for handling Errors
Closure<com.exalate.basic.domain.hubobject.v1.BasicHubCustomField> onNoCfFound,
Closure<com.exalate.basic.domain.hubobject.v1.BasicHubCustomField> onCfContextMismatch,
Closure<com.exalate.basic.domain.hubobject.v1.BasicHubOption> onNoOptionFound,
Closure<com.exalate.basic.domain.hubobject.v1.BasicHubUser> onNoUserFound,
Closure<com.exalate.basic.domain.hubobject.v1.BasicHubVersion> onNoVersionFound,

Do you have any examples of creating a closure for determining how to create the custom field for you if it does not exist?

You have a great example here for nfeed (https://docs.idalko.com/exalate/display/ED/How+to+sync+nfeed+fields+when+key+values+are+different) that can fetch the values required to populate the custom field.
Can this be expanded for singleselect, multiselect and cascadeselect custom fields?

You also have onNoUserFound Closure but this isn’t propogated to the CreateIssue.groovy and UpdateIssue.groovy scripts so it isn’t much use for creating (essentially non active) users.


Answer by Francis Martens (Exalate) on 08 September 2020

We don’t have that example in our toolbox.
Is this cloud or server?


Comments:

Stephen Atkinson commented on 09 September 2020

Hi Francis Martens (Exalate)I am working on Jira Server instances.

Francis Martens (Exalate) commented on 09 September 2020

Google is your frind :=) (I didn’t validate)
https://community.atlassian.com/t5/Answers-Developer-Questions/Create-Custom-Field-using-Groovy-Script/qaq-p/501997

I think you should be able to craft the logic required
Also check How to access a workload attribute provided by Tempo for an example who to access the services of an add-on (such as tempo)

What is your use case?