on 2016 Mar 07 12:41 PM
Hallo Community,
i do create an ExtendedCollection via BeanShel like this:
colln = bean.getExtensionCollection(collectionName);
while (...) {
collBean = colln.create();
ext_field = collBean.getExtensionField(FIELD_DOC_NAME);
ext_field.set(docName);
ext_field = collBean.getExtensionField(FIELD_DOC_VERSION);
ext_field.set(docVersion);
colln.add(collBean);
}
I add several doc names wit their versions.
After that i have to sort this collection according to DOC_NAME and DOC_VERSION
How can i do that?
thanks.
Waldemar
Request clarification before answering.
is there really no way to sort a extended collection?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hallo Bogdan,
thank you for your answer.
i tryed to do this this way:
class CustomListComparator implements Comparator {
public int compare(Object o1, Object o2) {
ExtensionFieldIfc e_name_1 = o1.getExtensionField(FIELD_DOC_NAME);
ExtensionFieldIfc e_name_2 = o2.getExtensionField(FIELD_DOC_NAME);
name_1 = e_name_1.get();
name_2 = e_name_2.get();
ret = name_1.compareTo(name_2);
if (ret == 0) {
ExtensionFieldIfc e_ver_1 = o1.getExtensionField(FIELD_DOC__VER);
ExtensionFieldIfc e_ver_2 = o2.getExtensionField(FIELD_DOC_VER);
ver_1 = e_ver_1.get();
ver_2 = e_ver_2.get();
ret = ver_1.compareTo(ver_2);
}
return ret;
}
}
public void sortCollection(IBeanIfc bean, String collectionName) {
ArrayList customArrayList = new ArrayList();
colln = bean.getExtensionCollection(collectionName);
for (iter = colln.size(); iter > 0; iter--) {
ExtensionCollectionMemberIfc extMember = colln.get(iter-1);
customArrayList.add(extMember);
}
for (iter = colln.size(); iter > 0; iter--) {
ExtensionCollectionMemberIfc extMember = colln.get(iter-1);
colln.delete(extMember);
}
Collections.sort(customArrayList, new CustomListComparator());
iterator = customArrayList.iterator();
for (list_member: iterator) {
colln.add(list_member);
}
}
But my problem is that i manipulate the extended collection and then try to sort it in the same step.
So i add or delete some members of the collection and then try to sort it.
When i do that the system tells me, that another user has already changed the collection and the changes are rejected. i have to press the "cancel" button.
You should only do such actions on VALIDATE (or toolbar scripts). Not LOADED, SAVED because these will have repercussions on system functionality. (recommend you to read carefully the Scripting and Workflow guide for SAP Sourcing, to understand how script contexts work)
Script context does not have any impact on your concurrency issue ... and there is no way to circumvent standard Java security.
As I said before, you could first sort your members in a separate List, then clear the extension collection and re-add them in the right order.
PS: I have not done this before, so it's just a recommendation as the easiest solution. There are also other ways to do this sort, but again I haven't tested any so I can't recommend.
Bogdan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.