cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ginko
Helper III
Helper III

How to substitute text with variable return data?

Per the screenshot below (and typed for convenience), I am retrieving text via the OnSelect property of the blue Autofill button and then place the retrieved text in the '1st SUB Item Name' text box via the Substitute formula. But the Substitute formula is doing nothing.

 

If the Default property of the '1st SUB Item Name' is "Trim(varautofill11_IM.DESCRIPTION)" it works, but I don't understand how to get the text replaced when the Autofill button is pressed. Is Substitute the wrong formula?

 

The key is that the '1st SUB Item Name' Default property needs to be both "ThisItem.FirstSUBItemName" BUT ALSO have the ability to be "varautofill11_IM.DESCRIPTION" if the text box is blank. And I simply don't know how to get there with the substitute formula not responding. Any advice would be huge in my understanding of these formula's!

 

autofill.png

UpdateContext({locShowSpinner: true});
Substitute(DataCardValue24_1.Text, DataCardValue24_1.Text, Trim(varautofill11_IM.DESCRIPTION));
//Set(AutofillWarning, true);
Set(varautofill11_RQ, LookUp(REQLINES, ITEM=DataCardValue14_1.Text));
Set(varautofill11_IM, LookUp(ITEM_MASTER, ITEM=DataCardValue14_1.Text));
UpdateContext({locShowSpinner: false})

 

1 ACCEPTED SOLUTION

Accepted Solutions
rubin_boer
Super User
Super User

hi @Ginko 

 

Please use this as a reference for substitute

 

rubin_boer_0-1654804378811.png

Substitute(DataCardValue24_1.Text, DataCardValue24_1.Text, Trim(varautofill11_IM.DESCRIPTION)) is the same as replacing the whole card.Text with Trim(varautofill11_IM.DESCRIPTION), its a replacement not substitute.

 

Consider this for the default of DataCardValue24_1:

Default = Coalesce(Parent.Default,Trim(varautofill11_IM.DESCRIPTION))) what happens here is when the defaut value is blank the other value will be shown 

 

I may have missed the context of your request, in that case please let me know.

 

Example

rubin_boer_1-1654804810540.png

 

Hope it helps,

R

View solution in original post

4 REPLIES 4
rubin_boer
Super User
Super User

hi @Ginko 

 

Please use this as a reference for substitute

 

rubin_boer_0-1654804378811.png

Substitute(DataCardValue24_1.Text, DataCardValue24_1.Text, Trim(varautofill11_IM.DESCRIPTION)) is the same as replacing the whole card.Text with Trim(varautofill11_IM.DESCRIPTION), its a replacement not substitute.

 

Consider this for the default of DataCardValue24_1:

Default = Coalesce(Parent.Default,Trim(varautofill11_IM.DESCRIPTION))) what happens here is when the defaut value is blank the other value will be shown 

 

I may have missed the context of your request, in that case please let me know.

 

Example

rubin_boer_1-1654804810540.png

 

Hope it helps,

R

Pstork1
Dual Super User
Dual Super User

I think your problem with your Substitute is that you are trying to directly change a property of a control in real time.  That doesn't work in Power Apps.  Instead set the default property equal to a context variable and then do your Substitute on that Context variable. Using the context variable as the default of the dataCardValue24 will then show the right value.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

You're right, if I am going to use substitute it has to be variable -> variable. The next problem is with the mixture of existing and blank entries, Rubin's coalesce seems to take care of that if I reverse the order of it. Thanks for confirming the context issue with my initial attempt!

Yep, you got it, I feel silly that first bit was the equivalent of saying 'RIP in peace' lol. It was so simple, I was so overcomplicating it. I ended up reversing the coalesce to Coalesce(Trim(varautofill11_IM.DESCRIPTION), Parent.Default)) because my business case makes marginally more sense to replace existing text, but both ways work well. Thanks so much on the substitute lesson and coalesce introduction!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,735)