cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Power Automate
Power Automate

icon sets data card value

does anyone know how to set the OnSelect of an icon (from insert >>icons) so that it sets the value of a data card value to a specific text value when pressed?

i tried : DataCardValue10.Value = "new value text"

but that throws an error

thank you for your help

audrie

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: icon sets data card value

You will need to use the Reset property of the DataCardValue object. A "true" value in the Reset property will cause the object to revert to whatever you set as the Default property.

 

 

icon1.OnSelect:

UpdateContext({resetvalue: !resetvalue});
UpdateContext({resetvalue: !resetvalue});
UpdateContext({newvaluetext: [whatever value you want]})

 

 

 

DataCardValue10.Reset:

resetvalue
DataCardValue10.Default:

newvaluetext

 

 

In PowerApps, you cannot directly use one object to tell an object to do something. UpdateContext allows you to create and store variables which you can use anywhere else on the screen. So one object will create newvaluetext, which another object will listen to indirectly.

 

The reason you need resetvalue twice in icon1 is because it triggers true to achieve what it needs, then goes back to false so it's ready to trigger again when needed.

 

 

Microsoft Employee
@8bitclassroom

View solution in original post

8 REPLIES 8
Highlighted
Community Champion
Community Champion

Re: icon sets data card value

You will need to use the Reset property of the DataCardValue object. A "true" value in the Reset property will cause the object to revert to whatever you set as the Default property.

 

 

icon1.OnSelect:

UpdateContext({resetvalue: !resetvalue});
UpdateContext({resetvalue: !resetvalue});
UpdateContext({newvaluetext: [whatever value you want]})

 

 

 

DataCardValue10.Reset:

resetvalue
DataCardValue10.Default:

newvaluetext

 

 

In PowerApps, you cannot directly use one object to tell an object to do something. UpdateContext allows you to create and store variables which you can use anywhere else on the screen. So one object will create newvaluetext, which another object will listen to indirectly.

 

The reason you need resetvalue twice in icon1 is because it triggers true to achieve what it needs, then goes back to false so it's ready to trigger again when needed.

 

 

Microsoft Employee
@8bitclassroom

View solution in original post

Highlighted
Power Automate
Power Automate

Re: icon sets data card value

You're AWESOME!!

{How about a mind meld?) Smiley Happy Heart

 

It will take me a while to get used to the idea of Context versus Set Value methodologies....but I understand.

Highlighted
Power Automate
Power Automate

Re: icon sets data card value

I encountered a problem with this approach. It works wonderfully when the edit form is for New Items, but unfortunately it prevents an existing value from showing up in edit mode. Would you know how to resolve that scenario?

 

Thank you again!

Highlighted
Community Champion
Community Champion

Re: icon sets data card value

This is where things get complicated.

 

There are three Default properties to be aware of: 

  • Form#.Items
  • DataCard#.Default
  • DataCardValue#.Default

 

When you use NewForm, the Form#.Items property is blank and that will trickle down to DataCard.Default and DataCardValue.Default, if they have not been changed from Parent.Default.

 

If you use ResetForm, the Form#Items property will be in effect. If DataCard.Default and DataCardValue.Default are still set to Parent.Default, then they will take on the corresponding column for that record.

 

I think as long as you made the edits to DataCardValue and not the other two, things should work out.

 

Otherwise, you may need to use a variable to detect whether you are in New mode or Edit mode.

And then based on the state of the variable, determine the default value. 

 

For every instance of:

NewForm(Form1)
or
ResetForm(Form1)

accompany it with: 

UpdateContext({edit: true/false})


So you end up with: 
NewForm(Form1);
UpdateContext({edit: false})

and
ResetForm(Form1);
UpdateContext({edit: true})
and adjust DataCardValue.Default to:

If(edit,Parent.Default,[your variable here])

This means, if you're editing an existing record, it will take on the value of the existing record. Otherwise, it will take the value of clicking your icon. From here, you'll need to tweak the condition to suit your needs--if a condition is needed.

 

 

Microsoft Employee
@8bitclassroom
Highlighted
Power Automate
Power Automate

Re: icon sets data card value

I'm going to try and see if I can do this.

 

Related question: Can I have a different New Form than Edit Form instead of having them together on one?

 

Thank you again!

Highlighted
Community Champion
Community Champion

Re: icon sets data card value

You can have Form1 and Form2 both tied to the same datasource. 

 

You can have all instances of Form1 as:

NewForm(Form1)

and all instances of Form2 as:

ResetForm(Form2)

I don't see a conflict here. It should work if you want to avoid the confusion of Default properties.

Microsoft Employee
@8bitclassroom
Highlighted
Power Automate
Power Automate

Re: icon sets data card value

So I got the form working again, but now the icons aren't working. Apparently I'm not quite understanding how to 'add' the feature without impacting others. I'm rereading and trying again. Thank you for your comments.

Highlighted
New Member

Re: icon sets data card value

Is it possible to have a form or data table with a list of items that you can change the quantity of with a plus or minus icon? For instance, a grocery list.

Apples _______
Bananas _______
Mangos _______

- +

The plus and minus icons would increase or decrease based on the filled selected.

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,052)