For every project, I have exactly one Tempo account (Tempo Timesheets product) defined that represents the support aspect of that project. It contains the word "Support" prefixed by something else ("Foo Support", "Bar Support", etc). The business wants to set the Account field when a support ticket comes in.
I have the JMWE add-on (awesome by the way!) and use it for many things, but I can't figure out how to produce a nunjucks script to achieve this. I've gone through Innovalog and Nunjucks docs.
As an example, I have these Accounts for a project TEST:
I need to loop through the set of Accounts associated with the project TEST and return the one with Support in its name and set the Account field to Foo Support.
For instance, this does not work (I tried the custom field's name and also tried "Account".
{{ issue.fields.customfield_12440 | find("Support") }}
Hi Paul,
unfortunately, this is not exactly easy on Jira Cloud. It requires a new feature (https://innovalog.atlassian.net/browse/MWEC-417) that will be released in the next version of JMWE for Jira Cloud (within a week) and some Nunjucks code:
{% set regex = r/Support/ %}
{% for account in "Account" | availableOptions %}
{% if regex.test(account.value) %}
{% set proj = account.config.scope.projects2 | find({id:issue.fields.project.id | int}) %}
{{ account.id if proj and not proj.attributes | find('notSelectable')}}
{% endif %}
{% endfor %}
This complicated code is required because you need to check, for each account that matches the regular expression, that it also is available for the project of the current issue (and the way Tempo expresses it is complicated and might change in the future).
Nice, David. You're always super helpful and extremely knowledgeable of your excellent product. I always appreciate your time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
David, perhaps I'm jumping the gun but I see your linked issue is fixed. I tried your exact syntax (above) on a create step's post function and get the below error in the JMWE log. Using the nunjucks tester, it returns two values split onto two rows: 86 on the first line and 88 on the second line. For this project, I have one Tempo Account attached to it called "ATR Support".
Error code:400
Error message:Unexpected response: 400
Detailed error(s):Option with id 0 not found
Method:PUT
Url:https://[paulstenant]/rest/api/2/issue/TST-731?overrideScreenSecurity=true&overrideEditableFlag=true¬ifyUsers=false
Data:Objectfields:Objectcustomfield_12440:0
Post-function:Set field value
Transition:Create Issue (from status None to status Open) of workflow PS Incident Workflow 4
Configuration:
Object
ignoreEmptyValue:false
conditionalExecution:false
sendNotifications:false
createMissingValues:false
valueIsJSON:false
executionDelay:10
_needsRefresh:truevalue:"{% set regex = r/Support/ %} {% for account in "Account" | availableOptions %} {% if regex.test(account.value) %} {% set proj = account.config.scope.projects2 | find({id:issue.fields.project.id | int}) %} {{ account.id if proj and not proj.attributes | find('notSelectable')}} {% endif %} {% endfor %}"
appendValues:false
_modified:"2019-07-17T16:43:23.687Z"
copyOnlyIfNotSet:false
fieldId:"customfield_12440"
runAsType:"addonUser"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Paul,
that's odd. It means the Nunjucks expression is finding _two_ accounts that match the regex and are active for the current project. Maybe there has been a change in Tempo's internal structures (which are not documented).
Can you open a support request on our support helpdesk (https://innovalog.atlassian.net/servicedesk/customer/portal/10) so we can look into the data Tempo returns on your instance?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I made a judgment error. I forgot that I have one global Tempo Account called "Enterprise Support" which is why it returned two accounts. Although the global account doesn't always display on all projects, we have to remember that if these exist, this exact nunjucks syntax won't work. Thanks to David for his guidance. I can either modify this regex or modify the name of the global account. Either way, my point is that this post function as prescribed above works wonderfully given how Tempo's API behaves today which as we know could change.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.