How to set Default value for Lookup Fields
Hello,
I have the current setup:
A Master List (the one we are working on) and a Sublist "Cost Centre" (Lookup) with Departments and the According Cost Centres.
When a new Item on the Masterlist is created I would like to set a default value for the field "Cost Centre" according to the department of the current User.
The Cost Center has to be changeable during and after the creation of a new item, so I only want to set a default value.
What would be the correct way to go about this?
I am working on SharePoint Online with Modern Forms.
Thanks and Best Regards
Thomas
-
Hi Thomas
You have to combine some functionalities for your use case:
- To set default value you can use the Initial Expression functionality on your Cost Center lookup field on the NewForm.
- To get a list entry from your Cost Center list based on a specific value use a query list function.
- The department of current user is accesible in Expression Builder -> [[@User.Profile.Department]]
In fact there is a challenge since the user's profile property placeholder is not working directly inside the query list function. Therefore you need to load this property on a Form Load Action and reuse it in the query list function.
1. Form Load Action:
window.userdepartment = [[@User.Profile.Department]]
2. Inital Expression with query list function:
=[[@Web.GetFirstValueForQuery('Cost Center', '<Where><Eq><FieldRef Name="Name"/><Value Type="Text">[[=window.userdepartment]]</Value></Eq></Where>', 'ID')]]
Result:
This selects the Cost Center entry on your form which has current user's department text in the "Name" field:
0
Please sign in to leave a comment.
Comments
1 comment