Skip to main content
October 9, 2024
Solved

How to put validation on pickerfieldusers which can select max 5 users

  • October 9, 2024
  • 25 replies
  • 0 views

Hi all,

I have a requirement as:

I have 2 pickerfieldusers as A and B where A can select max 1 user and B can select max 5 user, requirement is when we select user in A then B cannot select that user which is already selected in A and should throw validation error as "A user cannot be selected in B".

I tried putting validation as :

validations: {
if(
contains(
local!taskAdditionalAssignee,
ri!record['recordType!{a6f5f29e-a89e-495a-afae-702df167aa19}RECT Record Tasks Sync.fields.{d0fec037-4f71-4d05-a7ef-766635d0ff13}taskAssignedTo']
),
"Assignee cannot be added as additional assignee",
null
),

}

but when I open this form then as A and B both contains null value so same validation error throws comparing both A and b having null value which becomes similar

please help me how to achieve this

    Best answer by somasundaram.d

    Try including null check of the two variables

    if(
      and(
        a!isNotNullOrEmpty(local!taskAdditionalAssignee),
        a!isNotNullOrEmpty(local!usersOfPickerB),
        contains(
          local!taskAdditionalAssignee,
          ri!record['recordType!{a6f5f29e-a89e-495a-afae-702df167aa19}.fields.{d0fec037-4f71-4d05-a7ef-766635d0ff13}']
        )
      ),
      "Assignee cannot be added as additional assignee",
      null
    )

    25 replies

    October 10, 2024

    Hi [mention:f1719cb23da54416a6a4f5f27f3942cf:e9ed411860ed4f2ba0265705b8793d05] 

    Can you try this logic it may help you

    {
      a!pickerFieldUsers(
        label: "A",
        labelPosition: "ABOVE",
        maxSelections: 1,
        value: ri!inputA,
        saveInto: ri!inputA,
        validations: {}
      ),
      a!pickerFieldUsers(
        label: "B",
        labelPosition: "ABOVE",
        maxSelections: 4,
        value: ri!inputB,
        saveInto: ri!inputB,
        validations: {
          if(
            and(
              a!isNotNullOrEmpty(ri!inputA),
              a!isNotNullOrEmpty(ri!inputB),
              contains(ri!inputB, ri!inputA),
              
            ),
            "Can not select the A user ",
            {}
          )
        }
      )
    }

    October 10, 2024

    thankyou for your responce but still it is not fullfilling the requirement and i have 1 more question -

    If I have to choose max 5 user from pickerfielduser then at backened level what should be data type for that particular field as in my case data type is text and I m using recordtype to store data 

    for reference:  this field should hold atleast 5 user after submiting 

    somasundaram.d
    October 10, 2024

    Try including null check of the two variables

    if(
      and(
        a!isNotNullOrEmpty(local!taskAdditionalAssignee),
        a!isNotNullOrEmpty(local!usersOfPickerB),
        contains(
          local!taskAdditionalAssignee,
          ri!record['recordType!{a6f5f29e-a89e-495a-afae-702df167aa19}.fields.{d0fec037-4f71-4d05-a7ef-766635d0ff13}']
        )
      ),
      "Assignee cannot be added as additional assignee",
      null
    )

    October 10, 2024

    Thanks for your response but still not fulfilling my need as I have to store max 5 user but at backend level , field that should hold atleast 5 user is of text type.
    is it possible my field is of text type and i have to store 5 user ?

    somasundaram.d
    October 10, 2024

    I would advise you to create a new record called additionalAssignees, which will have one to many relationship with the existing record

    October 10, 2024

    It's better not to show the previously selected user(user selected in pickerFieldUsers field A) in the second pickerFieldUsers field (i.e. B).

    October 10, 2024

    is it possible that we can exclude the user in B which is  already selected in A?