use businessobject.clear() to clear all records?


Author
Message
Marcel Heitlager
Marcel Heitlager
StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)
Group: StrataFrame Users
Posts: 84, Visits: 835
This is a shorter post than the one I just previewed but didn't send.  But it is a newbie question anyway.

WHen you do BusinessObject.Add(), does that clear out the business object and then add a new row? Or do I need to do BUsinessObject.Clear() first if I want to clear all the values out?

Just double checking.

Thanks,

Marcel

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
WHen you do BusinessObject.Add(), does that clear out the business object and then add a new row?Or do I need to do BUsinessObject.Clear() first if I want to clear all the values out?




.Add will add a new row to the underlying datatable. It does not clear out the current data. Use this method when you want to add a new row. This will also update the EditingState of the BO and update any bound controls to the BO. Use NewRow() if you are just doing something programmatically (see the "Adding Editing & Deleting Records" help topic for more info).



.Clear clears all the data in the BO and resets the underlying datatable (thus if you add/deleted any columns, they are restored).



Hope that clears things up for you! BigGrin
StrataFrame Team
S
StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Yep, just like Greg says, Clear() reverts the business object back to square 1.  So, if you have 10 records in the BO, and you call .Add(), it will have 11, if you call Clear(), it will have 0.  I think part of your confusion might come from the fact that a BO can hold multiple records; if you are thinking that it can only hold one, then yeah, thinking you need to clear it before using it again would certaily make sense Smile
Marcel Heitlager
Marcel Heitlager
StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)
Group: StrataFrame Users
Posts: 84, Visits: 835
Thanks for your support, guys!

Just to make sure I got it - what is the recommened way to handle the following scenario?

I have a parent/child bo.

The user enters one parent record, and then he adds let's say 5 child records before he clicks finish (like with a wizard). For example I set up one company with 5 contacts.  Now after adding the five contacts, the user discover that contact #3 shouldn't have been added, so he removes him from the list. Finally the user is satisfied with the result and he clicks finish and the parent/child records are saved to the database.

To add a new record I simply use the add method.  What about deleting a record from that bo.  Simply use delete? How will that affect the final save?

Again I appreciate your help, and your framework has already saved me a considerable amount of work.BigGrin

Thanks,

Marcel

Marcel Heitlager
Marcel Heitlager
StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)StrataFrame User (202 reputation)
Group: StrataFrame Users
Posts: 84, Visits: 835
I just thought about it for a moment...can you do a simple revert on any record in a the dataset that you just added before the save? Or can you only do a revert on the current record you are working on?
StrataFrame Team
S
StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
You can handle this in a couple of ways. 

1) You can move to the record that you want to delete (MoveAbsolute to the index) and call DeleteCurrentRow().  The business object will see that the record is in an Added state (not saved to the database) and just reject the changes on it which will dump it, leaving you with 4 records. 

2) The other option is to move to the record (MoveAbsolute again) and call Undo() by passing the argument to indicate that you only want to undo the current row.  This will reject the changes on the row and since the row has not been saved, it has the same effect as deleting it.

Now, your best bet it probably #1, because that way you can use the same delete action for deleting new records that aren't saved, yet, and deleting records that are already saved (those ones are marked for deletion for when Save() is called).  If you use the Undo() method and it's a persisted record, it's just going to undo the changes you made since you retrieved it from the database.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search