Something went wrong while trying to load the full version of this site. Try hard-refreshing this page to fix the error.

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

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

Read the initial post here: CLEAR CONTEXT new command needed. Here's why (comment)
thats just to make sure you know about "Context"

And the solution has to be done with a SubProcess:
It there command action to Clear Context? (SOLVED)

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.


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, Pass data from one BO to another when record not found, 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.


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

JHew wrote

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

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.