Loop through two business objects and copy one to the other if not present in the list

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
JHew
Posts: 27
Joined: Thu Jun 25, 2020 12:23 pm

Loop through two business objects and copy one to the other if not present in the list

Post by JHew »

I have two BOs; One called Parts list and the other Validation. The users are in separate departments so cant use the same BO's as they're designed for different thing. One aspect however, is that the Validation team needs to update the records on the parts list to keep the information accurate. So I need to do two things that can be run from a process from the validation side.

First check if the record in the validation list is present in the Parts list using the Primary Key, if not create the record in the Parts List. Second if a record is in the parts list and not in the validation list remove it from the Parts list BO.

Does anyone have a process written to do this?

The closest I’ve got is:

Find ALL PartsList
Find ALL Validation

if PartsList.PKEY <> Validation.PKEY
Create PartList With PartsList.PKEY = Validation.PKEY,... and so on

All this does is create the same record multiple times. Haven’t even attempted to delete records yet as I can’t get past this first bit.

Thanks.
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Loop through two business objects and copy one to the other if not present in the list

Post by Jaymer »

yes, we can solve this easily
am looking for an already-posted example thread, or will post a fresh answer

but first read through this
https://www.awareim.com/forum/viewtopic.php?f=1&t=11482
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Loop through two business objects and copy one to the other if not present in the list

Post by Jaymer »

Read the initial post here: https://www.awareim.com/forum/viewtopic ... 720#p52720
thats just to make sure you know about "Context"

And the solution has to be done with a SubProcess:
https://www.awareim.com/forum/viewtopic ... subprocess

Which is how this was solved.
Except in your case, "Process1" will be "FIND ALL Validation"

Then your 2nd process knows about that set, and can
FIND PartsList WHERE PartsList = Validation.ps_Part (assuming you have a reference field from Validation -> Partslist) - OR
FIND PartsList WHERE PartsList.PartNum = Validation.PartNum
IF SEARCH_COUNT = 0 THEN CREATE ..... WITH ....

That does the 1st requirement.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Loop through two business objects and copy one to the other if not present in the list

Post by Jaymer »

That does it very "procedurally", and you (Aware) may have to do 99% unnecessary FINDs because most likely, only a FEW PartsList records need to be created.
BUT, that method reads easily and is straightforward.

From your older post, https://www.awareim.com/forum/viewtopic.php?f=1&t=11875, you could try the NOT(EXIST...) method to trim down the initial set of Validation records.

FIND Validation WHERE NOT(EXISTS PartsList WHERE PartsList.PartNum = Validation.PartNum)

This way, you're only finding the ones where there's not a match and then the subprocess doesn't have to do a FIND, it can just CREATE because only the Validation recs WHICH NEED A MATCHING PartsList record will be sent to it in CONTEXT.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
JHew
Posts: 27
Joined: Thu Jun 25, 2020 12:23 pm

Re: Loop through two business objects and copy one to the other if not present in the list

Post by JHew »

Thanks for your help. I did try and use the where not exist but it would give one of two errors: Internal error. GC overhead limit exceeded or Internal error. Java heap space. Not sure why. But the other way works perfectly so not to worry.

I managed to build on it to delete the records that dont exist in the validation list if anyones interested:

Except in your case, "Process1" will be "FIND ALL Validation"

Then your 2nd process knows about that set, and can
FIND PartsList WHERE PartsList = Validation.ps_Part (assuming you have a reference field from Validation -> Partslist) - OR
FIND PartsList WHERE PartsList.PartNum = Validation.PartNum
IF SEARCH_COUNT = 0 THEN CREATE ..... WITH ....

I added this to process 2:
IF SEARCH_COUNT > 0 Then PartsList.ValidationDate = CURRENT_TIMESTAMP


Then a thrid process
FIND PartsList WHERE PartsList.ValidationDate < CURRENT_DATE
DELETE PartsList
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Loop through two business objects and copy one to the other if not present in the list

Post by PointsWell »

JHew wrote: Thu Mar 04, 2021 3:06 pm The users are in separate departments so cant use the same BO's as they're designed for different thing.
I've been following this and I have an architecture question as the way it is designed at the moment suggests that there is synthetic redundancy here.

I'm interested in why you have made the statement above. Don't know if you have looked into access roles to restrict and limit access to forms and fields. The risk with having separate BO to manage the functionality of essentially the same tangible business object is the problem that you are now encountering, how to keep two separate lists of the same (or very similar) things synchronised.

I appreciate that you may have inherited someone else's design or have a system that is in production and therefore are prevented from making significant changes and also this doesn't answer the specific question you are asking. (I also acknowledge that I don't appreciate other people questioning my architectural decisions that often have a million other considerations in place that I might not have disclosed, so feel free to write off this post as "you don't understand the problem").
JHew
Posts: 27
Joined: Thu Jun 25, 2020 12:23 pm

Re: Loop through two business objects and copy one to the other if not present in the list

Post by JHew »

The long term plan is for the validation data to come from a different piece of software and feed into AwareIM. Once this is set up, the only requirement will be to do this check so it seemed cleaner to keep them separate.
Post Reply