Forums

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

C#/Java Retrieve timeestimate value

zfischer
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 5, 2021

I need to retrieve the value in the timeestimate and timeoriginalestimate fields. It looks like the field itself is a JsonlElement.ValueKind = Number

 

My code is as follows:

 string issueTime = !string.IsNullOrEmpty((string) singleIssue.fields.timeoriginalestimate)? (string)singleIssue.fields.timeoriginalestimate.ToString():"NULL";

 

[Note: I know I am casting the result to a string, this is only for testing to see if it would work]

When there is no value (i.e. null) the code passes, but as soon as there is a value in the ValueKind it throws an error.

 

Can anyone help me to pull the value out of the field?

1 answer

1 accepted

2 votes
Answer accepted
zfischer
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 5, 2021

So, I finally figured it out after searching online. Here is what I did:

This is the windows forms code (C#):

[singleIssue is the list of issues returned from Jira]

-----------------------------------------------------------------------------------------------

if (singleIssue.fields.timeestimate != null)
{
timeEstimate =
GetValueKindNumber((System.Text.Json.JsonElement)singleIssue.fields.timeestimate);
}

 

Here is the private method used to deal with all related fields with VauleKind values:

---------------------------------------------------------------------------------------------

private int GetValueKindNumber(JsonElement jsonElement)
{
int valueKindResult = 0;
if (jsonElement.ValueKind == JsonValueKind.Number)
{
valueKindResult = (int)jsonElement.GetSingle();
}

return valueKindResult;
}

Suggest an answer

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

Atlassian Community Events