Hi,
I want to use a Json code in Jira Automation in the additional field section in wich I want to update the due Date of an issue with a customfield (date picker).
At first I implemented this and this works but only when the customfield_10015 is not empty.
{
"fields": {
"duedate": "{{issue.customfield_10015}}"
}
}
But what I want is that the duedate is set to "None"/ Empty" when the customfield_10015 is also empty. But Json needs always a value.
So I tried this:
{
"fields": {
{{#if(not(triggerissue.customfield_10015.isEmpty))}} "duedate":"{{issue.customfield_10015}}"{{/}}
}
}
But I get an error in the automation.
UPDATE:
When I try this and the customfield is not empty the automation works and the duedate gets the same value like the customfield_10015.
But when the customfield_10015 is Empty/ does not exists the Automation does not work and I get an error.
{
"fields": {
{{#if(not(exists(issue.customfield_10015)))}} "duedate": null
{{/}} "duedate": "{{issue.customfield_10015}}"
}
}
The expression you show will create invalid JSON when the field is empty / null, resulting in this:
{"fields": {"duedate": null "duedate": "someDateValue"}}
Try instead only making the field value dynamic:
{"fields": {"duedate": {{#if(not(exists(issue.customfield_10015)))}}null{{/}}"{{issue.customfield_10015}}"}}
This will always add the field name, followed by either the text "null" and the value null, or the actual date value from the field when it is not null.
UPDATE: there is an answer which works at the end of this thread.
Kind regards,
Bill
@Bill Sheboy
I implemented your solution
And when the customfield_10015 is not empty then it works, but when the customfield is empty I still run in an error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also tried this:
{
"fields": {
"duedate": {{#if(issue.customfield_10015.isEmpty)}}null{{/}}"{{issue.customfield_10015}}"
}
}
Same behaviour. It works when customfield_10015 is not empty, but it runs in an error when customfield_10015 is Empty:
It seems like the condition does not work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In that case I believe you will need two conditions for this scenario, as null appears not to be enclosed in quotation marks, according to your testing.
Try adding one for the is empty and one where it is not, adjacent to each other.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy Thank your for your reply. What exactly do you mean?
Like this?
{
"fields": {
"duedate": {{#if(issue.customfield_10015.isEmpty)}} null{{/}}
{{#if(not(issue.customfield_10015.isEmpty))}} "{{issue.customfield_10015}}" {{/}}
}
}
It still runs in an error when customfield_10015 is Empty since "(The duedate must be of the format "yyyy-MM-dd" (duedate))".
The code works when the customfield_10015 is not Empty. I do not unterstand what is wrong with the code.
It seems like the value "null" is not accepted here. @Bill Sheboy Do you have any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My apologies for the detours...After some testing, I found a bit of inconsistency in the date field checks for isEmpty(), and consistency for isNotEmpty(). Thus we can invert the problem and use this form of the if() function:
{{if(someBooleanTest, trueValueToReturn, falseValueToReturn)}}
Which works out to this for your scenario:
{
"fields": {
"duedate": {{if(issue.customfield_10015.jiraDate.isNotEmpty(), issue.customfield_10015.format("\"yyyy-MM-dd\""),"null")}}
}
}
How this works is: use an explicit format() for the date, forcing the addition of the escaped quotation marks to the layout. For the null value, the quotation marks are not needed, and they are consumed by the if() function when it returns a value.
This one is getting saved with my example rules :^)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Bill thank you for your reply. I was able to solve my problem in meantime.
The following code works:
{
"fields": {
"duedate": {{#if(not(equals(issue.customfield_10015,null)))}} "{{issue.customfield_10015}}" {{/}} {{#if(equals(issue.customfield_10015,null))}}null{{/}}
}
}
But now I have a problem with cascading list fields:
I know for single/multi-select fields I have to adjust the code the following:
{
"fields": {
"customfield_10853":{{#if(not(equals(issue.customfield_10853,null)))}} {"value":"{{issue.customfield_10853}}"} {{/}}{{#if(equals(issue.customfield_10853,null))}}null{{/}}
}
}
But what is with cascading fields. I tried this but it does not work:
{
"fields": {
"customfield_10686":
{{#if(not(equals(issue.customfield_10686,null)))}} {"value":"{{issue.customfield_10686.value}}","child":{"value": "{{issue.fields.customfield_10686.child.value}}"}} {{/}}{{#if(equals(issue.customfield_10686,null))}} {"value":null, "child": {
"value": null}} :{{/}}
}
}
I got the error that the child issue has no value. Any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I do not have much experience with cascading fields in rules, however I expect both the "parent" and child values would need to be checked for null...leading to more complicated conditions, possibly with nested conditions. (That is possible although tricky to get correct due to the permutations of null handling.)
I recommend using created variables to build up the JSON, writing it to the audit log to confirm it works for the different cases, and testing it incrementally. Do this before sending web requests to reduce the impact on your site usage limits for automation rules: https://www.atlassian.com/blog/announcements/cloud-automation-packaging-update
As the scope of this thread seems to be expanding, I'll return to a question which others asked earlier: what problem are you trying to solve by doing this?
I recall you noted needing conditional JSON to send a web request; however the limitations of rules may make getting a request in the desired format challenging. Consider instead sending the entire issue (which Send Web Request supports) and allowing the receiving service's code parse the data, perhaps more easily.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Maximilian,
Why are you doing that with JSON and not just updating the Due Date field normally in the rule ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Because this above is just an example of my problem.
I need conditional logic within JSON because I am using a Web request to create an issue and I want do set different attributes directly in the Web request.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The above code is just an easy example in order to test conditional logic within JSON
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please post your entire rule then - we can't help without knowing the proper details. There's nothing in your question that still would not allow you to update the field directly as the JSON in the advanced section is still just updating the field using information from the trigger.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using a rule in order to create automatically a Jira project by using Rest API.
In the same automation I use additional Web requests to create specific issues, filters and boards in the new created project ({{newProjectID}}.
Next to mandatory attributes like "summary, Reporter, issuetype etc. I want also to update optional fields like customfield_10853 from triggerissue to new Issue which should be created by the Web request.
But the web request is only successful when the triggerissue has data in all defined custom fields. I was expecting that when the value of customfield_10853 in triggerissue is null then the customfield_10853 in the new issue should be also null. But that does not work. JSON is expecting a value.
So i tried to use conditional logic within the JSON code but it works only sometimes. For better testing I tried to test my Code logic with a more simple example like above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can have this type of condition in the payload.
Add a validation in the rule before executing the copy of the filed value.
First check is the custom field has a value, if it doesn't the rule will stop with a no action performed message in the rule audit log.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have 20 customfields which are copied in the JSON code. I can not do if condition outside of the JSON for all cases.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You don't need the "More fields" section to copy the due date from the trigger issue. Just select it in the "Choose fields to set" and put the smart value directly into there.
See if that works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If that still doesn't work for an Empty value, you could do an If/Else on the Date value.
If it is empty, you can set the Due Date to "{{clear}}" as stated in this post : Solved: How to use automation to clear date value on chang... (atlassian.com)
otherwise set the value to the custom field's value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, thank you. I know that I can implement a If condition outside of the action and the additional field section.
But I have a more complex use case in which I using the Additional field section to update the attributes of an issue during the creation process of the issue by using Web Request action and Jira Cloud Rest API.
Therefore I need conditional logic inside the additional section or the possibility to set a default value when the field is empty.
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.