Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
+1
person also asked this
people also asked this
Replies
6 replies
Subscribers
5 subscribers
Views
4118 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
Process
Adding Items in a Grid
tonyc
over 7 years ago
I created a grid in SAIL. I have managed to add and delete rows and capture the values. One of the columns in my grid calculates the difference in days between two dates. I need to have a field called Summary of Total Days contain the total of all those differences. I created an integer field on my interface but am having difficulties making that calculation. This is the code I have in my add a row rule to calculate the difference:
a!integerField(
label: "Total Days" & ri!index,
value: todate(ri!items[ri!index].endDate)-todate(ri!items[ri!index].startDate),
saveInto: ri!items[ri!index].amount,
validations: {}
),
Is my saveInto statement at fault. I am trying to bring back the value back into my interface that calls it. I have attached a screen shot of the interface that the customer would see.
OriginalPostID-271614
Discussion posts and replies are publicly visible
0
Rama Thummala
Certified Lead Developer
over 7 years ago
@tonyc
Move the calculation to saveInto like
value: ri!items[ri!index].amount,
saveInto:{
a!save(
ri!items[ri!index].amount,
todate(ri!items[ri!index].endDate)-todate(ri!items[ri!index].startDate),
)
}
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
venkateshamu
A Score Level 2
over 7 years ago
Hi tonyc,
From my understanding you want to calculate the difference automatically when user enters both dates. If this is the scenario you want then you have to Place these save function in both start date field and end date fields saveinto, so it will store difference into the target variable when he enters/modifies the start/end date. check null values as below code.
if(
or(
isnull(ri!items[ri!index].endDate),
isnull(ri!items[ri!index].startDate)
),
{},
a!save(
ri!items[ri!index].amount,
todate(ri!items[ri!index].endDate)-todate(ri!items[ri!index].startDate),
)
)
Hope this may help you... Correct me if i am wrong..
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Josh
Certified Lead Developer
over 7 years ago
Is your total read only or does it need to be editable?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
tonyc
over 7 years ago
read only
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Josh
Certified Lead Developer
over 7 years ago
Ok. In your example, the total field takes in an index variable, which doesn't make sense to me because I believe you want to total the differences for every record in the grid, not just at a specific index. If my assumption is correct, you would want your value in your integer field to be something like: "value: sum(apply(rule!getDifferences(start: _, end:_) merge(ri!items.startDate, ri!items.endDate)))" where rule!getDifference is a rule you create that returns "ri!endDate - ri!startDate". The apply will loop over every item in your array and will return a list of all the differences i.e. {3, 15, 20. 5}. When you wrap sum() arround this array, you will get the the sum of all the numbers in the array. Hope this helps!
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Mike Schmitt
Certified Lead Developer
over 7 years ago
I agree with Josh's suggestion, and will go one further step in suggesting that you calculate the value of the "totals" field in a WITH() variable, something like
with(
local!dayTotalSum: sum(
apply(
rule!getTotalDaysForItem,
ri!items
)
)
and in this example, you could make rule!getTotalDaysForItem handle the individual Item CDT and do that calculation (and handle null checks, and missing data on either side, etc).
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel