Hello,
I have a list variable with store the name and email.
I want to remove the item from the list, so I am using List Remove to remove the item.
To get ID for item I used aggregate to get the ItemID and used server action to delete the Item.
Whenever I try to remove it doesn't delete the selected item.
I have attached the AOP file.In this I have a list of subjects. I added subjects directly from database.
While removing the subject, suppose I have 4 subject A,B,C,D and I try to remove D then C will be removed instead of D.
Click of minus icon to remove subject and refresh the page.
Thanks in advance
Hi @Raj1010
I have implemented the logic to remove item from the list. I just updated the logic based on your OAP. Iam attaching the OML. Please check and let me know if you have any issues.
Regards
Mahesh
Thanks, this works perfect
Hi @Raj1010 ,
Please share your OML if possible.
Regards,
Kundan Chauhan
I have attached it
Hi Raj,
Please follow the below steps to delete a particular item from a list variable,
1. Use listIndexOf action to know the exact position of an item from the list variable.
2. From the listindexOf action, you will receive an position of the item in the list variable.
3. Use that position result in the list remove action to delete the record.
If any clarification, let me know.
thank you.
It is not removing the selected item. If I try to remove A it will remove B.
Hi,
You mentioned that you had used aggregate to id right.
Make sure that you pass name and email as filter to the condition, and use the ID in DELETE action.
If possible you can share the error message that you get when you delete the message.
Thanks
I'm not sure I understand the connection between the list and the database. Removing an item from a list is something altogether different from removing an item in the database.
What is it you are trying to achieve, and what exactly doesn't work as expected?
I have used List variable to get all Item from aggregate.GetItem.List -> AppendList in UI
Now I want to remove the item from the List. I have attached the aop file you can have a look
Hello @raj1010
Add a local variable to store the selected SubjectID. On the button/icon click, set the SelectedSubjectId. Create a server action to delete the subject using the SelectedSubjectId. After deletion, refresh the aggregate to update the list
i hope it helps!
Hello Anushka,
I am not using ID. I am using name then I am getting ID based on name selected
Now, if I try to remove subject A with ID 7 then some other value is getting removed and while debugging I can see selected item is not A its always something else.
ok raj
step by step:
Define a structure for subjects with Name and ID.
Create local variables to store the selected subject name and the list of subjects .Bind the dropdown or list widget to SelectedSubjectName
Create a server action RemoveSubjectByName that takes SelectedSubjectName as an input.
In this action, retrieve the ID based on the Name and then delete the subject using the retrieved ID
Add a button to trigger the removal of the selected subject.
Bind the button's action to the RemoveSubjectByName server action.Ensure the subject list is refreshed after the removal action to reflect the changes
I have added id in the list and in the remove server action i passed List.current.id still it delete some random value.
Hi @Raj1010,
I tried simulating your problem, here I am attaching sample OML. Hope It will help you.
Hi Mahesh,
After adding item to list I am also adding it into the table. So basically it will check for duplicate value in table if its unique it will add or display error. Adding logic works fine.
While removing, I can remove from List but when I pass Id in server action to delete it from table some random item is deleted not the selected one.
In order to delete item from a list using List Remove you have to pass index of list item. So if you want to delete a item and you have id of that item, them you have to write the logic to get the index of that id in the list where you want to delete then you can easily delete it.
Shashi Kant Shukla