Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Json formating with smartvalue

Peter Skokan December 6, 2023

hello all,

i'm doing lookup  with 2 if statements and i want output in json that looks like this :
{{#lookupIssues}}
{{#if(equals(Billed.value, "Billed"))}}
{
"Issue_ID":"{{key}}",
"Task":"{{summary}}",
"Time":"0:0",
"TimeInvoiced":"{{#=}}{{worklog.timeSpentSeconds.sum.divide(3600)}}+{{subtasks.timetracking.timeSpentSeconds.sum.divide(3600)}}
{{/}}h",
"Solutionist": "{{assignee.displayName}}"
}{{^last}},{{/last}}
{{/}}
{{#if(equals(Billed.value, "Non-Billed"))}}
{
"Issue_ID":"{{key}}",
"Task":"{{summary}}",
"Time":"{{#=}}{{worklog.timeSpentSeconds.sum.divide(3600)}}+{{subtasks.timetracking.timeSpentSeconds.sum.divide(3600)}}
{{/}}h",
"TimeInvoiced":"0:0",
"Solutionist": "{{assignee.displayName}}"
}{{^last}},{{/last}}
{{/}}
{{/}}
],

i have problem that it's putting comma after every item, even after last one ...
{{^last}},{{/last}}   should put comma only if the item is not last but it's not working :-/
can anyone help me on this ??

usually i have between 10-50 item in lookupissues...

 

1 answer

1 accepted

2 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 6, 2023

Hi @Peter Skokan -- Welcome to the Atlassian Community!

The challenge with a expression like this one is your {{^last}}... handling is outside of the point when the expression can detect if there is a value or not for both conditions.

It appears the variable part of your planned JSON is swapping the Time and TimeInvoiced values between 0 and the worklog values.  Is that correct?

If so, I recommend restructuring to have only those two fields inside of the filtering / conditional logic.  Then the iterator can properly detect the last record when it reaches the Solutionist information at the end, and so only one {{^last}}... will be needed.

Kind regards,
Bill

Peter Skokan December 6, 2023

Hello @Bill Sheboy 

yes your recommendation working ! thank you, i did not realize i can use it like that.

Like Bill Sheboy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 6, 2023

Awesome; I am glad to learn that helped.

Please consider marking this question as "answered"; that will help others in the community with a similar need find solutions faster.  Thanks!

Like Peter Skokan likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events