cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
adzaba
Regular Visitor

Change one field based on specific value of another in a SharePoint List Form.

Hi all, I'm new to Power Apps - please be gentle!

 

I'm using a form to update a SharePoint List.

The form has (among others) the following fields:

  1. AssignedTo (person)
  2. AssignedBy (person)
  3. AssignmentDate
  4. Completed? (yes/no)
  5. CompletionDate

I'd like AssignedBy and AssignmentDate to populate with current user and today respectively if AssignedTo is changed from null to not null.

I'd like CompletionDate to populate with today if Completed? changes from "no" to "yes"

 

I know I have to do something with onChange and Default values but I'm floundering.

 

Any help much appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
StalinPonnusamy
Super User
Super User

AssignedBy 

If(
    !IsBlank(Parent.Default),
    Parent.Default, If(!IsBlank(AssignedToDataCardValue.SelectedItems),
    {
        DisplayName: User().FullName,
        Claims: "i:0#.f|membership|" & Lower(User().Email),
        Department: "",
        Email: User().Email,
        JobTitle: "",
        Picture: ""
    },Blank())
)

 

AssignedDate

If(
    !IsBlank(Parent.Default),
    Parent.Default, If(!IsBlank(AssignedToDataCardValue.SelectedItems),
    Today(),Blank())
)

 

CompletionDate

If(
    !IsBlank(Parent.Default),
    Parent.Default,
    If(       
       ThisItem.'Complete?'.Value,
       Today(),
       Blank()
    )
)

 

  • I assume ThisItem.'Complete?'.Value produces value yes or no
  • Change AssignedToDataCardValue to yours

View solution in original post

5 REPLIES 5
StalinPonnusamy
Super User
Super User

Hi @adzaba 

 

Set DefaultSelectedItems Property of AssignedBy Person field to

 

If(
    !IsBlank(Parent.Default),
    Parent.Default,
    {
        DisplayName: User().FullName,
        Claims: "i:0#.f|membership|" & Lower(User().Email),
        Department: "",
        Email: User().Email,
        JobTitle: "",
        Picture: ""
    }
)

 

 

Set the DefaultDate property of AssignmentDate field to

 

If(
    !IsBlank(Parent.Default),
    Parent.Default,
    Today()
)

 

Set DefaultDate of CompletionDate to

If(
    !IsBlank(Parent.Default),
    Parent.Default,
    If(
        ThisItem.Completed,
        Today(),
        Blank()
    )
)

 

Note: Please make sure to update Completed field name

 

StalinPonnusamy
Super User
Super User

Hi @adzaba 

 

Correction:

 

Set DefaultDate of CompletionDate to

    !IsBlank(Parent.Default),
    Parent.Default,
    If(
        DataCardValue1.Value,
        Today(),
        Blank()
    )

Note: Change DataCardValue1.Value to the control on your screen

 

adzaba
Regular Visitor

@StalinPonnusamy Thanks so much for the response - I tried these. 

 

The assigning fields populate the correct fields but they do it whenever there is no value already in the field. I want it to be triggered only when AssignedTo changes from empty to not empty. So, for example, if I open the the form to change some other field not mentioned here but there is no value in AssignedTo, this script still auto-populates the AssignedDate and AssignedBy  when I don't want it to.

 

The completion fields don't work at all. I'm fully open to the thought that I'm doing something wrong to cause it though. Your code produced an error which I tried (unsuccessfully) to fix.

 

If(
    !IsBlank(Parent.Default),
    Parent.Default,
    If(
       // DataCardValue25.Value, // tried this - it kept giving an invalid argument error
       ThisItem.'Complete?'.Value = "Complete", // the syntax here seems ok but still doesn't work
       Today(),
       Blank()
    )
)

 

Thanks again.

StalinPonnusamy
Super User
Super User

AssignedBy 

If(
    !IsBlank(Parent.Default),
    Parent.Default, If(!IsBlank(AssignedToDataCardValue.SelectedItems),
    {
        DisplayName: User().FullName,
        Claims: "i:0#.f|membership|" & Lower(User().Email),
        Department: "",
        Email: User().Email,
        JobTitle: "",
        Picture: ""
    },Blank())
)

 

AssignedDate

If(
    !IsBlank(Parent.Default),
    Parent.Default, If(!IsBlank(AssignedToDataCardValue.SelectedItems),
    Today(),Blank())
)

 

CompletionDate

If(
    !IsBlank(Parent.Default),
    Parent.Default,
    If(       
       ThisItem.'Complete?'.Value,
       Today(),
       Blank()
    )
)

 

  • I assume ThisItem.'Complete?'.Value produces value yes or no
  • Change AssignedToDataCardValue to yours
adzaba
Regular Visitor

Thanks @StalinPonnusamy  - this is great. Much appreciated.

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Kudoed Authors
Users online (2,280)