Step 1: Search for all the business objects
1 Indexed String $businessObjects := ['Process', 'Screen', 'Data Class', 'Script Function', 'Document', 'Document Set', 'PDF Output', 'PDF Output Table', 'Rule', 'Rule Set', 'Catalog', 'Integration Link', 'Report', 'Resource', 'Test Data', 'Label', 'Primitive Type']:String;
Step 2: Create the list which the modified business objects need to be added to
1 String $List := 'c8437efe-ef69-4513-9ddc-aefffb17c5bd';
This is the ID you will get in the URL bar when we open the required custom list.
Step 3: Get the CustomList object
1CustomList $c;
2 $c := CustomListById($List);
Step 4: Get all the business object already present in the list
1 Indexed BusinessObject $objects := CustomListContent($c);
Step 5>Now we need to get all the businessobjects modified by a specific user within the a period of time, and check whether the business object is already present in the list or not.
If present then remove that business object from the list and then add recently modified one.
1 $clonedList := CAST(CustomList, $c.deepClone());
2 ForEach $businessObject In $businessObjects Do
3 Indexed BusinessObject $filteredBussObjectList;
4 BusinessObject $item;
5 $filteredBussObjectList := FILTER(GETBUSINESSOBJECTS($businessObject, VersionFilter('HeadFilter')), AND(EQUAL($userId, $item.getModifier()), ($item.getModificationTime() > TIMESTAMP(TIMEADD(NOW(), JOIN('-', $periodDate, 'D'))))), $item);
6 ForEach $bu In $filteredBussObjectList Do
7 If $clonedList.getContainerContent().contains($bu.getObjectRef()) Then
8 $clonedList.removeContainerObject($bu.getObjectRef());
9 End
10 // PRINTLN('$clonedListBEFORE-', $clonedList.getContainerContent());
11 PRINTLN('BUSINESSOBJECT TO BE UPDATED--', $bu);
12 $clonedList.addContainerObject($bu.getObjectRef());
13 // PRINTLN('$clonedListAFTER-', $clonedList.getContainerContent());
14 $c := $clonedList;
15 CONTEXT().getBusinessObjectRepository().update($c);
16 End
17End
Here we did deep clone of the required list because the original list would show as lock and we can not use addContainerObject function on the original list.
Here $periodDate is the period i.e no. of days within which the modified business object needs to be added to the list.