6 Replies Latest reply on Jan 23, 2018 2:42 AM by Mark6785

# using a calculation on a query

This seems like real basic stuff, but i'm struggling

I'm trying to use a calculation to create an extra column on a query.

I thought the easiest way to do this would be create an attribute, put the calc in it and then add this to the query columns, is there an easier way?

When I do this the column always comes up empty. The calculation is this:

import System

static def GetAttributeValue(Incident):

Value =  Incident.CreationDate - Incident.IsBreached

Value = "test"

return Value

Its supposed to just find the difference between the Creatin time and the breach time to show how much time the SLA has allowed for that job.

I put the extra line in to just output "test" as a test in case the calc is wrong , but still no result seems to come out.

Anyone know why this is?

What would the "calculation type" be on the attribute?

• ###### 1. Re: using a calculation on a query

What is the attribute Inicident.IsBreached?  This is a OOTB attribute in our system, which is a Boolean, so you wont be able to use it in a date / time calc.

Check out this https://community.ivanti.com/docs/DOC-8623

Darren

• ###### 2. Re: using a calculation on a query

Ah , Well spotted Darren.

I meant to use "breach time" , which also seems to be an OOTB box attrib holding a time and date.

I've corrected that , but the results are the same - empty column.

• ###### 3. Re: using a calculation on a query

What type of attribute did you create?

This should work for a String Attribute:

```import System
static def GetAttributeValue(Incident):
return String.Format("{0} Hour(s), {1} Minute(s), {2} Second(s)", Math.Floor(TimePeriod.TotalHours), TimePeriod.Minutes, TimePeriod.Seconds)
```
• ###### 4. Re: using a calculation on a query

Interesting... with that I get one entry in the new column (out of about 47 rows!)

• ###### 5. Re: using a calculation on a query

Yes that looks correct as a BEFORESAVE calculation wont backfill existing transactions.  You could switch to AFTERREAD type but be mindful of the performance impact of that type of calc; if the data is static then BEFORESAVE is better (and sortable!).

If you want to do that then temporarily switch it to a scheduled calculation and then create a Schedule Manager job to update the calcs for all open requests.  Once run switch back to BEFORESAVE again.

Julian

MarXtar Ltd

• ###### 6. Re: using a calculation on a query

Thanks Fellas , I now have the whole column filled