cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ali1
Frequent Visitor

No Items to Display error OR New Item created when not needed

Hi all, I seem to be running into what seems to be a simple issue but I cannot figure out the fix. All data is being saved to a Sharepoint List. Let me begin by sharing my code (added to the OnStart section for the App):

 

```

// Obtain username and email of the logged-in user

Set(varLoggedInUser, User());



// Find the user with a matching email in the App Users list

With(

{wUserRecord: LookUp(LSS_TRACKER, Uzer.Email=varLoggedInUser.Email)},

Set(varUser, wUserRecord.FullName);

Set(varRole, wUserRecord.LSSRole.Value);

Set (varID, wUserRecord.ID);

Set(CurrentUserFirstName, Office365Users.MyProfile().GivenName);

Set(CurrentUserFullName, Office365Users.MyProfile().GivenName & " " & Office365Users.MyProfile().Surname)

);



// If matching user is not found, insert a new user into the list with the role User

If(IsBlank(varRole),

With(

{wUserRecord:

Patch(

LSS_TRACKER,

Defaults(LSS_TRACKER),

{

LSSPersonName: CurrentUserFullName,

Uzer: {

'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",

Claims:"i:0#.f|membership|"& varLoggedInUser.Email,

Department: "",

DisplayName: varLoggedInUser.FullName,

Email: varLoggedInUser.Email,

JobTitle: "",

Picture: ""

}



}

)

},

Set(varUser, wUserRecord.FullName);

Set(varRole, wUserRecord.LSSRole.Value);

Navigate(NewUser,ScreenTransition.Cover);

),

Navigate(AdminView,ScreenTransition.Fade);

);

 

What this does is:

1. Check if current user exists or not.

2. IF exists go to a certain Screen.

3. If does NOT exist then

4. Create the user (plus fill in a few additional fields on the SP List).

5. Go to another screen with another Form to complete additional user details to current item

 

The problem is in the last step for a User who does not exist. After creating the user it goes to the screen called `NewUser` which contains a form BUT if the form is set to Edit mode then I get a `No Items to Display` message

 

If Form is set to EditModeIf Form is set to EditMode

 

If I set the form to New then I can interact with the form but when its time to submit (There is a button with the code `SubmitForm(UserInputFields)`in the OnSelect section).

 

If Form Set to NewModeIf Form Set to NewMode

 

A New item is created, which is not what I need: 

 

IfFormSet_NewMode3.png

I need it to update the current item (in this example - the one with the ID 59) not create a new one, what am I doing wrong here?

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @Ali1 ,

 

According to your description, I think you should use edit form instead of new form in the 5th step. The edit form shows 'no item to display' because the formula of the item attribute of your form is wrong .

 

Please try this formula:

 

// Obtain username and email of the logged-in user

Set(varLoggedInUser, User());

 

// Find the user with a matching email in the App Users list

With(

{wUserRecord: LookUp(LSS_TRACKER, Uzer.Email=varLoggedInUser.Email)},

Set(varUser, wUserRecord.FullName);

Set(varRole, wUserRecord.LSSRole.Value);

Set (varID, wUserRecord.ID);

Set(CurrentUserFirstName, Office365Users.MyProfile().GivenName);

Set(CurrentUserFullName, Office365Users.MyProfile().GivenName & " " & Office365Users.MyProfile().Surname)

);

 

// If matching user is not found, insert a new user into the list with the role User

If(IsBlank(varRole),

With(

{wUserRecord:

Patch(

LSS_TRACKER,

Defaults(LSS_TRACKER),

{

LSSPersonName: CurrentUserFullName,

Uzer: {

'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",

Claims:"i:0#.f|membership|"& varLoggedInUser.Email,

Department: "",

DisplayName: varLoggedInUser.FullName,

Email: varLoggedInUser.Email,

JobTitle: "",

Picture: ""

}

 

}

)

},

Set(varUser, wUserRecord.FullName);

Set(varRole, wUserRecord.LSSRole.Value);

Set(varID),wUserRecord.ID);
Refresh(LSS_TRACKER);
Navigate(NewUser,ScreenTransition.Cover);

),

Navigate(AdminView,ScreenTransition.Fade);

);

 

Then you could set the Item property of your form control to :

LookUp(LSS_TRACKER,ID=varID)

 

Best Regards,

Wearsky

View solution in original post

4 REPLIES 4
vwyankee
Helper V
Helper V

The form needs to be in edit mode with the "Item" Property looking up the ID of the new user SP item that was just created. Set a variable from your wUserRecord.ID to use in your form Item property as the lookup. If not clear, I can give an example.

Ali1
Frequent Visitor

Hi @vwyankee , Thanks for replying and yes please an example would be really helpful! 

v-xiaochen-msft
Community Support
Community Support

Hi @Ali1 ,

 

According to your description, I think you should use edit form instead of new form in the 5th step. The edit form shows 'no item to display' because the formula of the item attribute of your form is wrong .

 

Please try this formula:

 

// Obtain username and email of the logged-in user

Set(varLoggedInUser, User());

 

// Find the user with a matching email in the App Users list

With(

{wUserRecord: LookUp(LSS_TRACKER, Uzer.Email=varLoggedInUser.Email)},

Set(varUser, wUserRecord.FullName);

Set(varRole, wUserRecord.LSSRole.Value);

Set (varID, wUserRecord.ID);

Set(CurrentUserFirstName, Office365Users.MyProfile().GivenName);

Set(CurrentUserFullName, Office365Users.MyProfile().GivenName & " " & Office365Users.MyProfile().Surname)

);

 

// If matching user is not found, insert a new user into the list with the role User

If(IsBlank(varRole),

With(

{wUserRecord:

Patch(

LSS_TRACKER,

Defaults(LSS_TRACKER),

{

LSSPersonName: CurrentUserFullName,

Uzer: {

'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",

Claims:"i:0#.f|membership|"& varLoggedInUser.Email,

Department: "",

DisplayName: varLoggedInUser.FullName,

Email: varLoggedInUser.Email,

JobTitle: "",

Picture: ""

}

 

}

)

},

Set(varUser, wUserRecord.FullName);

Set(varRole, wUserRecord.LSSRole.Value);

Set(varID),wUserRecord.ID);
Refresh(LSS_TRACKER);
Navigate(NewUser,ScreenTransition.Cover);

),

Navigate(AdminView,ScreenTransition.Fade);

);

 

Then you could set the Item property of your form control to :

LookUp(LSS_TRACKER,ID=varID)

 

Best Regards,

Wearsky

Thanks so Much @v-xiaochen-msft  I was trying out what @vwyankee  had recommended and had figured out the LookUp thing but the key was the Refresh command! That got the App to read and store the ID properly! Thanks a bunch!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,819)