GetSelectionMembersArchiveRows return wrong members-count

lock
push_pin
done
Answered
7

A crm-script on an online customer, that has been running for 3 years, where I use members from a selection, suddently starts returning wrong member-count. I guess it can be from latest release 10.1.6.

2 examples (both dynamic person selections) return 4752 and 8102 members, where the selection from the GUI returns 0.

If I look through the returned members, the criteria for these members doesn't match the criteria set in the selection. E.g. the run selection in the GUI seems to return the correct number, where the sript returns wrongly.

I tried to create the selections from scratch with the same results.

Has there been any changes to this class in the latest version?

  NSArchiveListItem[] members = selAgent.GetSelectionMembersArchiveRows(setApsisSelectionId, "");
  printLine(members.length().toString()); 

28 Sep 2022 | 11:15 AM

All Replies (7)

We experience the same thing using the API in addition to CRM Script.

To add on a little, if we update the members through the selection UI (the refresh button in the bottom right) our CRMScript actually updates (Not until we update the selection though), but the API is still returning the wrong members. This could be caused by the user running the CRMScript being the same user that refreshed the list, while we use a system user to communicate with the API.

28 Sep 2022 | 11:40 AM

Hi Kasper,

The SelectionAgent doesn't use the same search logic as the New Selection/Find function in the UI. The new stuff uses the Find Selection API, which could explain the difference you are observing.

 

28 Sep 2022 | 11:41 AM
We are also using the SelectionAgent in both cases, but the agent is returning the right members, when we refresh the selection.
It is returning the right members in the CRMScript that is.
28 Sep 2022 | 11:45 AM
Hi Tony,
Should I read your answer as the agent doesn't work anymore then? Because in either cases I would expect the same results. The selection is quite simple (as selections can be ;) ) - only 3 criterias with AND and no OR.
28 Sep 2022 | 12:02 PM

It looks like there has been some changes to 10.1.6 which breaks the SelectionAgent class. 

I don't have a overview of how many solutions use this class, but it can be critical if it just stops working without any warnings. 

29 Sep 2022 | 12:36 PM

There has not been any logic changes in the SelectionAgent in many months. The last changes were to for the v9.2 release to adapt to GetSeletionMembersArchiveRows  to use the new Find/Selection APIs, and therefore should give you the same results you see inside the SuperOffice Selection page.

 

 

29 Sep 2022 | 01:24 PM

Hi Tony. 

It is still weird, because this has worked flawlessly until 28/09/2022 for the customer. If not the selectionAgent, then something else must have changed.

Using the ArchiveAgent I'm still not sure how to get either a member count, or a list of members from a selection with a given selectionId.  I have read the article you have linked to. Maybe I don't understand it, but it only gives an example of how to create a selection without any criterias.

30 Sep 2022 | 06:32 AM

Sample code to retrieve selection archive rows based on the new find system (so by using the specific archive provider):

#setLanguageLevel 3;
NSSelectionAgent selectionAgent;
NSArchiveAgent archiveAgent;

Integer selectionId = 144;

// retrieve selection entity to retrieve the corrent provider name and entity name
NSSelectionEntity selectionEntity = selectionAgent.GetSelectionEntity(selectionId);

NSArchiveRestrictionInfo[] restrictions;

// restrict on the selection id of the selection we want to get the members of
NSArchiveRestrictionInfo selectionRestriction;
selectionRestriction.SetName("selectionId");
selectionRestriction.SetOperator("Equals");
selectionRestriction.SetValues(String(selectionId.toString()).split(",")); 
restrictions.pushBack(selectionRestriction);

// no specific order specified
NSArchiveOrderByInfo[] order;

// specifiy the main selection entity
String[] entities = String(selectionEntity.GetTargetTableName().toLower()).split(",");

if (selectionEntity.GetTargetTableName().equalsIgnoreCase("contact"))
{
  	entities.pushBack("person");
}

NSArchiveListItem[] rows = archiveAgent.GetArchiveListByColumns(selectionEntity.GetMainProviderName(), String("appointmentId").split(","), order, restrictions, entities, 0, 2147483647);

print(rows.length().toString());

 

Would it not be better for backwards compativility to change the implementation of the GetSelectionMembersArchiveRows to use the correct archive provider in the background?

30 Sep 2022 | 12:17 PM
Thank you. Ill def. take a look on this!
3 Oct 2022 | 10:11 AM
Im getting the following error. I have tried changing 'appointmendId' to 'personId' or 'contactId' but with no luck. The targeted selection is a find-person-selection.

The Selection archive list provider requires a valid, nonzero selectionId restriction using the '=' operato
3 Oct 2022 | 10:33 AM
I think you get that error due to the line:
selectionRestriction.SetOperator("operatorEquals");
It should just be:
selectionRestriction.SetOperator("Equals");
3 Oct 2022 | 10:36 AM
Now it compiles, but it gives me 0 each time I run it.
3 Oct 2022 | 10:39 AM
Person is a special case, since then you need to specify 2 entities for archive agent. (contact and person).

I updated the sample code to account for that.
3 Oct 2022 | 10:52 AM
Hi David.

Thank you. Funny. Now your code gives the same result as 'selectionEntity.GetMemberCount()' - both which are wrong. The selections shows 7474 in GUI, but scripts returns 12881 in both cases.
3 Oct 2022 | 11:16 AM

If it is indeed for persons, then the logic that GetSelectionMembersArchiveRows is nearly identical to the code David has shared. So, if you have any more details you would like to share in attempt to recreate this behavior, by all means share it. 

3 Oct 2022 | 09:39 AM

Add reply