How to add members to a static selection using entities layer
The example demonstrates the use of entities to achieve the task.
using(SoSession session = SoSession.Authenticate("SAL0", ""))
//retrieve the contact that owns the persons we want to add as members
//to our static selection
Contact myContact = Contact.GetFromIdxContactId(21);
//retrieve the selection that we want to add members to
Selection staticSelection = Selection.GetFromIdxSelectionId(65);
//lets loop through the persons of the contact and the them to the
// selection as its members
int i = 0;
if (myContact.Persons.Count > 0)
foreach (Person myPerson in myContact.Persons)
//create a new selection member row
SelectionMemberRow newRow =
//set the default values
//assign the contact ID
newRow.ContactId = myContact.ContactId;
//assign the person ID
newRow.PersonId = myPerson.PersonId;
//add rows of the selection member rows collection one by
// one to the retrieved static selection entity
//finally save the selection entity
Here we have retrieved the contact entity that the persons that we want to add as members to the static selection belong to.
Now we can loop through the person collection of the contact entity and add the persons one by one as members of the static selection.
This example only adds persons from one contact, but if you want you may add persons from many contacts as members of a static selection. Also, you can notice the contact ID and the person ID has not been hard-coded, but if you want to this is also a possibility.
If you are adding members to a static selection by hard coding the contact ID and the person ID, or if you are getting these values from a user interface input, you must make sure that the person ID belongs to a person that belongs to the contact ID you are specifying for a given