How to add members to a static selection using the services layer
Example 1
using SuperOffice.CRM.Security;
using SuperOffice.CRM.Services;
using SuperOffice;
using(SoSession session = SoSession.Authenticate("SAL0", ""))
{
//create a Selection agent
SelectionAgent selectionAgent = new SelectionAgent();
//create a contact agent
ContactAgent contactAgent = new ContactAgent();
//retrieve the contact entity of the persons that you want to add as
//members to the selection that you want
ContactEntity myContact = contactAgent.GetContactWithPersons(21);
if (myContact.Persons.Length > 0)
{
//create a array of ContactPersonIds and add the array to the selection
ContactPersonId[] personId = new ContactPersonId[3];
for (int i = 0; i<3; i++ )
{
personId[i] = new ContactPersonId();
personId[i].ContactId = myContact.ContactId;
personId[i].PersonId = myContact.Persons[i].PersonId;
}
//add the members to the selection
selectionAgent.AddContactSelectionMembers(65, personId);
}
}
In the above example, we create all the agents we require. We have used the methods provided in the contact agent to retrieve the contact we want to add its persons to a selection.
We have used the AddConactSelectionMembers
method of the selection agent to add the members to a static selection. As you can see, the second parameter of the method is an array of ContactPersonId
objects. In the example, we loop through the persons
array of the contact entity and adding the person IDs to the ContactPersonId
array. By doing this, we do not need to add the specific person_id
, but if we want it’s also possible to add a new selection member by person_id
. As one can see, we have added only one contact person to the selection, but if we want we can add persons from different contacts to a static selection.
Example 2
Below is an example that shows how we can add members from different contacts to a static selection. Here we hard code the contact_id
and person_id
.
using SuperOffice.CRM.Security;
using SuperOffice.CRM.Services;
using SuperOffice;
using(SoSession session = SoSession.Authenticate("SAL0", ""))
{
//create a Selection agent
SelectionAgent selectionAgent = new SelectionAgent();
//create a contact agent
ContactAgent contactAgent = new ContactAgent();
//retrieve the contact entity of the persons that you want to add as
//members to the selection that you want
ContactEntity myContact = contactAgent.GetContactWithPersons(21);
if (myContact.Persons.Length > 0)
{
//create a array of ContactPersonIds and add the array to the selection
ContactPersonId[] personId = new ContactPersonId[3];
for (int i = 0; i<3; i++ )
{
personId[i] = new ContactPersonId();
personId[i].ContactId = myContact.ContactId;
personId[i].PersonId = myContact.Persons[i].PersonId;
}
//add the members to the selection
selectionAgent.AddContactSelectionMembers(65, personId);
}
}
Note
We have given the Contact_id
and the Person_id
to each element of the ContactPersonId
array. Always give the number of a person belonging to the contact that we specify for that element. For example, in the person
table, the person with person_id=83
must have a person.contact_id=35
.