Changing the BO's editing state to new with values already filled.


Author
Message
Vikram Saxena
Vikram Saxena
StrataFrame Beginner (41 reputation)StrataFrame Beginner (41 reputation)StrataFrame Beginner (41 reputation)StrataFrame Beginner (41 reputation)StrataFrame Beginner (41 reputation)StrataFrame Beginner (41 reputation)StrataFrame Beginner (41 reputation)StrataFrame Beginner (41 reputation)StrataFrame Beginner (41 reputation)
Group: Forum Members
Posts: 41, Visits: 99
I have added a custom button on the SF Maintenance form to copy the current row values of the business object. on the clicked event of the button(copy) what i am doing is

1-> Store the Current Row,

2-> Begin a new row for BO.

3-> fill the values by fetching from data row we have in 1-> .

4-> invoke edit on the BO.



here is the code.



DataRow currentRow = employeeBO1.CurrentRow;

employeeBO1.NewRow();

for (int i = 0; i < currentRow.ItemArray.Length; i++)

{

employeeBO1.CurrentRow[i] = currentRow[i];

}

employeeBO1.Edit();



Till this everything is working very fine but the problem occurs when i click save and there is any broken rules exists on the form. i got the message that There are 'X' broken rules present.

when i click on the form to correct the values ...Zing...the new record gone..i reached to the last record that i copied. This works fine if there are no broken rules present for the new record....Please help...its very urgent..
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Well, your code is kindof a dangerous copy Smile  You are not taking into account any primary key fields, etc.  If your business object is managed your PKs or your database is auto-incrementing, then this is not going to work because the second row is the same as your first...including the PK which should be handed out.

You may need to take your PK and FK fields into account when copying.

Chan
Chan
Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

Can you provide any sample code to copy record?

Any plan to add copy feature to SF.NET? As this is quite a common function and been asked many times in forum.



Thank you
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
It depends on the table row that is being copied.  For example:

Private Sub CopyRow(ByVal SourceBusinessObject As BusinessLayer, ByVal FieldsToSkip As System.Collections.Generic.List(Of String))
    '-- Establish Locals
    Dim loTemp As MyBO
    Dim loColumn As DataColumn

    '-- Copy the data into the temp BO
    loTemp.CopyDataFrom(SourceBusinessObject, StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromDefaultView)

    '-- Set the index to the temp BO
    loTemp.SeekToPrimaryKey(SourceBusinessObject.MyPK)

    '-- Create a new row in the source BO
    SourceBusinessObject.NewRow()

    '-- Cycle through the columns
    For Each loColumn In SourceBusinessObject.CurrentDataTable.Columns
        '-- Check for skipped fields
        If FieldsToSkip.Contains(loColumn.Columnname) Then
            Continue For
        End If

        '-- Copy the data
        SourceBusinessObject.CurrentRow.Item(loColumn.ColumnName) = loTemp.CurrentRow.Item(loColumn.ColumnName)
    Next

    '-- Clean Up
    loTemp.Dispose()
   
End Sub


StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
You can do a foreach loop through the columns of the CurrentDataTable and if the columns are included in the PrimaryKeyFields array, then don't copy them. 

As for the problem with the row disappearing... there is a property called AutoNavigateToFirstBrokenRow; try setting it to false and see if that fixes your problem.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
1-> Store the Current Row,

2-> Begin a new row for BO.

3-> fill the values by fetching from data row we have in 1-> .

4-> invoke edit on the BO.




To avoid the whole PK issue, I'd just change the logic a smidge:



1. Store away the current row

2. Invoke Add on BO

3. Set all the data properties in the new row to those saved in step 1

4. Invoke Save on BO.

5. Invoke Edit on BO if you want user to edit the new copy.



This way however the BO is managing the PK will be honored and you're UI will automatically be navigated to the new copy...if I understand the problem correctly. Hope this helps Smile
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