cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
PytByt
Level 8

Using IfError function with 2 patch

Hi all..

 

I need to know that what i'm doing is right.
I using the IfError Functiong here with 2 ForAll Patch form collection into my D365 Entities like below:

IfError(
ForAll(ScanColl, Patch(InventoryCountingJournalLines,
LookUp(InventoryCountingJournalLines, JournalNumber = Journals.SelectedText.Journal
&& ItemNumber=item_id && InventorySiteId=item_site
&& WarehouseId=item_warehouse && WarehouseLocationId=item_location),
{CountedQuantity:item_count}))
,
ForAll(ScanColl, Patch(InventoryCountingJournalLines,
Defaults(InventoryCountingJournalLines),
{JournalNumber: Journals.SelectedText.Journal,
ItemNumber: item_id,
ItemBatchNumber: item_batchnumber,
InventorySiteId: item_site,
WarehouseId: item_warehouse,
WarehouseLocationId: item_location,
CountedQuantity: item_count})))

I want to know if this the best practice that i could get for getting the return value for error if a record is already exist in my DS, then i go and create it as a new record with my second patch. 
The idea is, if a record that already exist in my DS, then i created it as new record in my DS.

Also, i need to know how i can get a retur value for using IfError or Error function.

Please help.

Any work around with the Error function is welcome.

Regards,
PytByt

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Using IfError function with 2 patch

Hi @PytByt ,

Could you please share a bit more about your scenario?

Do you want to check if the specific record has been existed in your Entity, if not, create as a new one, otherwise, modify the existing one?

 

Based on the needs that you mentioned, I afraid that the IfError function could not achieve your needs. Even though, there is no matched record existed in your Entity, the first ForAll formula in your IfError function would be still executed. If there is no matched record existed in your Entity, the LookUp(...) formula in your first ForAll function would return a Blank record, then the first Patch function would add new record into your Entity rather than edit existing record (same functionality as your second Patch).

Note: In other words, the ForAll or Patch function formula within your IfError function would not return a error value.

 

I have made a test on my side, please take a try with the following workaround:

Set the OnSelect property of the "Submit" button to following:

ForAll(
ScanColl,
If(
!IsBlank(LookUp(InventoryCountingJournalLines, JournalNumber = Journals.SelectedText.Journal && ItemNumber=item_id && InventorySiteId=item_site && WarehouseId=item_warehouse && WarehouseLocationId=item_location)),
Patch( /* <-- Edit existing records */
InventoryCountingJournalLines,
LookUp(InventoryCountingJournalLines, JournalNumber = Journals.SelectedText.Journal && ItemNumber=item_id && InventorySiteId=item_site && WarehouseId=item_warehouse && WarehouseLocationId=item_location),
{
CountedQuantity: item_count
}
),
Patch( /* <-- Add new records */
InventoryCountingJournalLines,
Defaults(InventoryCountingJournalLines),
{
JournalNumber: Journals.SelectedText.Journal,
ItemNumber: item_id,
ItemBatchNumber: item_batchnumber,
InventorySiteId: item_site,
WarehouseId: item_warehouse,
WarehouseLocationId: item_location,
CountedQuantity: item_count
}
)
)
)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Community Support Team
Community Support Team

Re: Using IfError function with 2 patch

Hi @PytByt ,

Could you please share a bit more about your scenario?

Do you want to check if the specific record has been existed in your Entity, if not, create as a new one, otherwise, modify the existing one?

 

Based on the needs that you mentioned, I afraid that the IfError function could not achieve your needs. Even though, there is no matched record existed in your Entity, the first ForAll formula in your IfError function would be still executed. If there is no matched record existed in your Entity, the LookUp(...) formula in your first ForAll function would return a Blank record, then the first Patch function would add new record into your Entity rather than edit existing record (same functionality as your second Patch).

Note: In other words, the ForAll or Patch function formula within your IfError function would not return a error value.

 

I have made a test on my side, please take a try with the following workaround:

Set the OnSelect property of the "Submit" button to following:

ForAll(
ScanColl,
If(
!IsBlank(LookUp(InventoryCountingJournalLines, JournalNumber = Journals.SelectedText.Journal && ItemNumber=item_id && InventorySiteId=item_site && WarehouseId=item_warehouse && WarehouseLocationId=item_location)),
Patch( /* <-- Edit existing records */
InventoryCountingJournalLines,
LookUp(InventoryCountingJournalLines, JournalNumber = Journals.SelectedText.Journal && ItemNumber=item_id && InventorySiteId=item_site && WarehouseId=item_warehouse && WarehouseLocationId=item_location),
{
CountedQuantity: item_count
}
),
Patch( /* <-- Add new records */
InventoryCountingJournalLines,
Defaults(InventoryCountingJournalLines),
{
JournalNumber: Journals.SelectedText.Journal,
ItemNumber: item_id,
ItemBatchNumber: item_batchnumber,
InventorySiteId: item_site,
WarehouseId: item_warehouse,
WarehouseLocationId: item_location,
CountedQuantity: item_count
}
)
)
)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

PytByt
Level 8

Re: Using IfError function with 2 patch

Hi @v-xida-msft 

thank you for your reply.

Do you want to check if the specific record has been existed in your Entity, if not, create as a new one, otherwise, modify the existing one?
Yes

Based on the needs that you mentioned, I afraid that the IfError function could not achieve your needs. Even though, there is no matched record existed in your Entity, the first ForAll formula in your IfError function would be still executed. If there is no matched record existed in your Entity, the LookUp(...) formula in your first ForAll function would return a Blank record, then the first Patch function would add new record into your Entity rather than edit existing record (same functionality as your second Patch).
Could you please explain more about this, i'm confused.

I also want to implemented this within a collection, is that possible?
I currently using this on my Button OnSelect Property:

ClearCollect(PatchColl,
Patch(InvColl,
First(Filter(InvColl, ItemBatchNumber = batchNumber
&& WarehouseId = Loc_WHID && WarehouseLocationId = Loc_WHLocID)),
{CountedQuantity: Value(TextInput_Qty.Text)}));

If(
Not(IsEmpty(PatchColl)),
Notify("Patch Count Success", NotificationType.Success)
,
Collect(ScanColl,
{item_barcode: Label_ScannedCode.Text,
item_batchnumber: Scan_BatchNumber.Text,
item_site: Loc_siteId,
item_id: Scan_ItemId.Text,
item_name: 'Scan_Item(Name)'.Text,
item_warehouse: Loc_WHID,
item_count: Value(TextInput_Qty.Text),
item_expiry: Scan_Expiry.Text,
item_location: Loc_WHLocID}));

 
From my formula above, it seems like the logic is not right. 
What i about to do is:
1. Pull data from D365FO int a Collection (InvCOll)
2. Test if i cant patch update the Quantity Column in InvColl
3. If Not, i collect the collection. (should i create new collection?)

What should i do best?

Thanks,

BR.
PytByt

 

Community Support Team
Community Support Team

Re: Using IfError function with 2 patch

Hi @PytByt ,

Have you specified a Required/Mandatory field within your D365 Entity?

 

The IfError function tests one or more values until it finds an error result. If you do not specify a Required/Mandatory field within your D365 Entity, the following Patch formula would not return error value regardless of whether or not an matching record is existed in your Entity:

Patch(
InvColl, First(Filter(InvColl, ItemBatchNumber = batchNumber && WarehouseId = Loc_WHID && WarehouseLocationId = Loc_WHLocID)), {CountedQuantity: Value(TextInput_Qty.Text)}
)

The First(Filter(...)) formula would return a valid record or a Blank record. If it returns a valid record, the Patch function would modify the existing record, if it returns a Blank record, the Patch function would add a new record into your Entity.

 

For your second question, the PatchColl collection would still be populated with proper record rather than Blank regardless of whether or not the First(Filter(InvColl, ItemBatchNumber = batchNumber
&& WarehouseId = Loc_WHID && WarehouseLocationId = Loc_WHLocID)) formula return a valid matching record or a Blank record.

 

Please consider take a try with above alternative solution I mentioned, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 296 members 2,907 guests
Please welcome our newest community members: