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
Replies
19 replies
Subscribers
7 subscribers
Views
6444 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
General
Adding a new row in a grid(interface)
sowjanyav430
over 7 years ago
Hi
I want to auto increment a user defined id in a grid when a new row is added.
I was able to increment the id but facing an issue...
Test scenario:
Add 2 new rows,delete the 1st row,
again add a new row.
In this scenario am getting the repeated id.
This is because i have used grid row index for id increment,
Please refer the attached screenshots for more details.
Can anybody suggest me how to handle this scenario.
Thanks in advance.
OriginalPostID-239262
Discussion posts and replies are publicly visible
0
Vinay Kumar Rai
over 7 years ago
Yes the same thing the above code do
Use below code on "gridRowLayout", to show EmployeeId in run time
a!textField(
value:
if(len(ri!CDT[ri!Index].employeeId)=0,
concat("INC-",stripwith(ri!CDT[ri!Index].employeeId,"INC-")+ ri!Index)
,concat("INC-",right(year(today()),2),0,0,0,ri!CDT[ri!Index].employeeId)
)
)
and when user finally submit, use the above rule "TEST_Format_EmployeeId" to evaluate the EmployeeId
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sikhivahans
over 7 years ago
@sowjanyav At a high level, what I could say is, if you are assigning the values(NOT displaying) to a field upon adding a row to the grid, make sure that upon deletion of rows in the grid, certain operations are performed which will refresh the assigned values. For instance, let's say you have added 10 rows as per your logic, and now deleted certain rows of your wish. Now it's your responsibility to reassign the fresh values back to the field upon each deletion. Because it's you that has assigned values upon adding a row and again it should be you who should refresh and reassign the values upon deletion.
Your delete link's saveInto should additionally perform a similar operation: (For time being let's assume we are using 1,2,3 and so on for employeeId.)
{
\t/*This will reassign the fresh values to the employeeId field upon deleting a row in the middle, or at first or last.*/
\tif(
\ trule!APN_isEmpty(ri!SVG_IAL1_Employee),
\ t{},
\ ta!save(
\ tri!SVG_IAL1_Employee.employeeId,
\ tenumerate(fn!length(ri!SVG_IAL1_Employee))+1
\ t)
\t)
}
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sikhivahans
over 7 years ago
Also, I would like to comment on the few approaches as mentioned in the above comments:
1. Using a separate variable to retain id or depending on the database may not be wise. The value in the database may change at any time and this change in values confuses the User. Keep it simple, assign temporary ids and let the user know that they are temporary and going to change when persisted to the database. The much simpler thing would be to show the row id which keeps the implementation simple and also makes one easily understandable about it.
2. I am not really sure why the suggestion is being made to show/display values rather than assigning them to a field in the CDT. Again it's not a wise idea to evaluate such a rule for each and every row when you have a possibility of assigning and refreshing them by making use of add/delete dynamic links. Even from the interface performance standpoint, it's not great because the value which is assigned to a text field looks simple but it will be evaluated for each and every row as and when you interact with each component on the interface(whereas refreshing the assigned values can be done only when interacted with grid).
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sowjanyav430
over 7 years ago
@sikhi..
it was not asked to display the generated id,instead am doing that on my own interest.
This might not be a wise idea but still i wanted to learn how to display...
Also i have tried the above mentioned code snippet....unfortunately it didn't work
Can you please give any other idea........
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sikhivahans
over 7 years ago
Nvm, I am talking about the solutions given to you. Sure, try this and let me know how it went:
{
if(
rule!APN_isEmpty(ri!SVG_IAL1_Employee),
{},
a!save(
ri!SVG_IAL1_Employee,
apply(
type!(
employeeId:_,
firstName:_,
lastName:_
),
merge(
enumerate(fn!length(ri!SVG_IAL1_Employee))+1,
ri!SVG_IAL1_Employee.firstName,
ri!SVG_IAL1_Employee.lastName
)
)
)
)
}
Please make sure that the above code snippet runs post remove operations on items and itemsToken variables. Also, bear in mind that the entire ri!SVG_IAL1_Employee CDT should be available to gridRowLayout rule.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sikhivahans
over 7 years ago
*type!SVG_IAL1_Employee(
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
gaurava322
over 7 years ago
this is a good use case, were you able to resolve it.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sowjanyav430
over 7 years ago
@sikhi and gaurav :
I haven't resolved this issue yet..
but sure will try and let you know...
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sikhivahans
over 7 years ago
@sowjanyav No worries, give us a shout in case if you need anything.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
<