Skip to main content

Search

How to set Default value for Lookup Fields

Comments

1 comment

  • Christof Nussbaumer

    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.