I have an app built that grabs the current user's Supervisor and auto populates a hidden field. This works great for users who have Supervisors assigned, but the form will NOT submit if the current users doesn't have a Supervisor assigned (such as Directors).
if I add this code to the 'DefaultSelectedItems', it works great.
If(
EditForm1.Mode=FormMode.New,
{
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims: "i:0#.f|membership|" & Office365Users.Manager(User().Email).DisplayName,
DisplayName: Office365Users.Manager(User().Email).DisplayName
},
Parent.Default
)
How to I enhance this code to add a clause which will populate the Supervisor with a default user if one doesn't exist?
The only thing I can think of is to use a Flow to get the Manager information, so you can gracefully handle the error. The other thing you might want to think about is making sure everyone has a manger listed in AD even if the manager is themselves.
This is a creative solution that works! However, the users with no Manager see an error when the App loads:
Resource 'manager' does not exist or one of its queried reference-property objects are not present
Is there a way to suppress this red bar error?
Ok, I have an idea. In the OnStart of the App set a variable that will contain the user's manger. This will be the actual manager of the user if the user doesn't have a manger. Then in the default formula use the manager variable to set the claims information. My code is a little different but I think it will work unless I have some typos.
If you are testing in the studio you will need to run the App > Run OnStart to get the variables set for the first time.
App - OnStart
Set(varGetUsersManager, Office365Users.ManagerV2(User().Email));
Set(varUsersManager, If(IsBlank(varGetUsersManager.displayName), Office365Users.MyProfileV2(), varGetUsersManager));
Try this code as the DefaultSelectedItems formula
If(
EditForm1.Mode=FormMode.New,
{
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims: "i:0#.f|membership|" & varUsersManager.userPrincipalName,
DisplayName: varUsersManager.displayName
},
Parent.Default
)
WarrenBelz
146,645
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,997
Most Valuable Professional