samedi 3 août 2019

Xaf how to set a ObjectKey for a navigation item based on current user

I do have a business class called UsersInfo, which consists of User details. When the user clicks a navigation item named "MyDetails" it should direct the user to a detail view, where the user should able to view the current logged in user's user details.

I tried the following code,

private void showNavigationItemController_CustomShowNavigationItem(object 
sender, CustomShowNavigationItemEventArgs e)  
    {  
        if (e.ActionArguments.SelectedChoiceActionItem.Id == "MyDetails")  
        {  

            IObjectSpace objectSpace = 
Application.CreateObjectSpace(typeof(UsersInfo));  

            UsersInfo appUser = objectSpace.GetObjectByKey<UsersInfo> 
(Application.Security.UserId);  

            DetailView detailView = 
Application.CreateDetailView(objectSpace, "UsersInfo_DetailView_Copy", 
true, appUser);  
            detailView.ViewEditMode = 
DevExpress.ExpressApp.Editors.ViewEditMode.Edit;  
            e.ActionArguments.ShowViewParameters.CreatedView = detailView;  
        }  
    }

But, I am getting this error, "The ObjectKey is empty while the shortcut refers to a DetailView and there are '12' objects to show".

This error occurs because, if my table has only one row there would be no issue it would simply display the record in a detail view.

As I have multiple records in a table, it gets confused to display which record in the table.

so, it is need of an objectkey specifying the record in the table.

I also tried to add the objectkey to the navigation item in the desiner by specifying CurrentUserId(), but it doesn't help. It just hides my navigation key. can someone help me to resolve this error.

I am sorry, if i cannot able to acknowledge my issue to you guys clearly, with my poor english.




Aucun commentaire:

Enregistrer un commentaire