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

Excract Value from a collection if object exists if not use ThisItems value

Hi,

 

i'm trying to work out how to populate a label in a gallery using the value from a collection if the object is in the collection, and if it isn't use the orignal value from the gallery source. I've tried:

 

 

"Stock Availability: " & If(LookUp(colStockAvailable, ProductsID = ThisItem.ProductID)).AvailableStock, ThisItem.StockAvailability)

 

And

 

"Stock Availability: " & If(LookUp(colStockAvailable, ProductsID = ThisItem.ProductID), AvailableStock, ThisItem.StockAvailability)

 

But I can't seem to just get the value back I want which is AvailableStock. 

 

My collection collects items that are in an orders list based on a date range, in my orders list it works out how much stock is left of those items based on those dates.

 

Any suggestions would be great.


Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
gabibalaban
Super User
Super User

 

@mousman85 ,

"Stock Availability: " & 
Coalesce(
        LookUp(
 	colStockAvailable,
	ProductsID = ThisItem.ProductID).AvailableStock,
        ThisItem.StockAvailability
)

Hope it helps !

 

View solution in original post

4 REPLIES 4
KvB1
Solution Specialist
Solution Specialist

In your If function, you first need to check if the record in the other collection exists using a lookup. If this check returns true, you grab the AvailableStock of that record, If not, you return ThisItem.StockAvailability.

 

Something like this:

 

 

"Stock Availability: " &
If(
	Len(
		LookUp(
			colStockAvailable,
			ProductsID = ThisItem.ProductID
		).AvailableStock
     	)>1,
	LookUp(
		colStockAvailable,
		ProductsID = ThisItem.ProductID
	).AvailableStock,
	ThisItem.StockAvailability
)

 

 

gabibalaban
Super User
Super User

 

@mousman85 ,

"Stock Availability: " & 
Coalesce(
        LookUp(
 	colStockAvailable,
	ProductsID = ThisItem.ProductID).AvailableStock,
        ThisItem.StockAvailability
)

Hope it helps !

 

View solution in original post

thanks for the fast repsonse, this worked perfectly! Thanks again. 

Just a further question on this as i've not used the Coalesce function. If i need to update the ThisItem.StockAvailalbity with how much stock they are choosing but not update the back end list is that possible? Something like :

"Stock Availability: " & 
Coalesce(
        LookUp(
 	colStockAvailable,
	ProductsID = ThisItem.ProductID).AvailableStock,
        Lookup(Resource Items, ProductId = Gallery2.Selected.ProductID, ThisItem.StockAvailable - Gallery2.selected.inputtext2.text)
)

 I know the above won't work just wondering how I can update the ThisItem.StockAvailable, based on how much they have selected, and then return that if the remove it from the other list, I had this working with it patching the main list, but I no longer want to update the master list as I need the availability to be based on dates. Below is a screen grab of the PoC app i'm bulding. when they update the slider it adds it to a collection that shows in the gallery on the right, and when the click the trash can it removes it from the gallery. 

 

image.png

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,241)