Set the time spent based on a custom field

Annika
Contributor
July 12, 2022

I am trying to integrate Jira with another system and the integration does not allow me to directly integrate the estimates (Original, Remaining, Spent) so I have copied the values into their own custom fields. I can set the original and remaining estimates fine but not the time spent.

I am using JMWE to automate and found a build your own (scripted) post function that allows me to set the time spent to a fixed amount

{{ "/rest/api/2/issue/:issue/worklog" | callJira(verb=("post"), params={"issue":issue.key}, 
body={
"timeSpent": "1h"
}
) | dump(2) }} 

 This works fine except I want to use the value of the custom time spent field {{ issue.fields.customfield_10172 }} to set the value. 

I have tried to insert this as the following but

 "timeSpent": "{{ issue.fields.customfield_10172 }}h" 

"timeSpent": {{ issue.fields.customfield_10172 }}"h"

 
Does anyone have an idea of what to try next?

 

Thanks

1 answer

1 accepted

0 votes
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 12, 2022

Hi @Annika ,

What is the problem you are encountering with that attempt?

Also, what is the field type of customfield_10172 ?

Annika
Contributor
July 12, 2022

Hi David
Thanks for your response - I referenced the wrong custom field in my 

  • 10172 is original estimate (can copy the value into the Jira Original Estimate Field)
  • 10173 is remaining estimate (can copy the value into the Jira Remaining Estimate Field)
  • 10174 is time spent
  • ALL are number fields

If I put the customer field in front of the '' ''

{{ "/rest/api/2/issue/:issue/worklog" | callJira(verb=("post"), params={"issue":issue.key}, 
body={
"timeSpent": {{ issue.fields.customfield_10174 }}"h"
}
) | dump(2) }}

then the error I get is 

(string) [Line 3, Column 16] parseAggregate: expected colon after dict key

And if I put it inside of the ""

{{ "/rest/api/2/issue/:issue/worklog" | callJira(verb=("post"), params={"issue":issue.key}, 
body={
"timeSpent": "{{ issue.fields.customfield_10174 }}h"
}
) | dump(2) }}

then the response is

(string)
  Error: Unexpected response: 400
 Worklog must not be null.
 timeLogged: Invalid time duration entered.

 

 I am sure it is a syntax error and I have tried googling but no luck. 

Hope you can help :)

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 12, 2022

Hi @Annika 

actually, the correct syntax is:

{{ "/rest/api/2/issue/:issue/worklog" | callJira(verb=("post"), params={"issue":issue.key}, 
body={
"timeSpent": issue.fields.customfield_10174 + "h"
}
) | dump(2) }}

I believe this should work, although there might still be a conversion problem between number and string.

David

Annika
Contributor
July 12, 2022

That worked perfectly, thanks David 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events