Getting the list of contractor's contacts using a script
This article contains a script for displaying the list of contacts of a selected contractor in a block.
Script without PublicAPI
The script includes the following context variables:
context.Customer - Contractor-type variable, contains the selected contractor (e.g. in a user task before the script).
context.Contacts - Block-type variable (contains the ContactName property). When creating a new block element, its class name P_ContractorContactsDisplay_Contacts is used.
For the script to work correctly, add the following assembly:
EleWise.ELMA.CRM
Namespaces:
using EleWise.ELMA.CRM.Models;
using EleWise.ELMA.Model.Common;
using EleWise.ELMA.Model.Entities.ProcessContext;
using EleWise.ELMA.Model.Managers;
Script:
var contractors = EntityManager<Contractor>.Instance.Find(FetchOptions.All); //get the list of all contractors
contractors.ForEach(k => {
if (k == context.Customer) //if the contractor matches the searched one
{
k.Contacts.ForEach(cont => { //then get the list of contacts of this contractor
var item_b = new P_ContractorContactsDisplay_Contacts(); //for each contact in the list, create a block element
item_b.ContactName = cont; //and write the contact to the created element
context.Contacts.Add(item_b); //add the created element to the block
});
}
});
Creating a similar script using PublicAPI
Documentation on PublicAPI is available here
Context variables:
context.Customer - Contractor-type variable
context.Contacts - Block-type variable (contains the ContactName property - Contact-type variable)
When creating a new block element, its class name P_GetContactList_Contacts is used.
Namespace:
Script:
context.Contacts - Block-type variable (contains the ContactName property - Contact-type variable)
When creating a new block element, its class name P_GetContactList_Contacts is used.
Namespace:
using EleWise.ELMA.API;
using Elewise.ELMA.Extensions;
var contractor = PublicAPI.CRM.Contractor.Find(FetchOptions.All);
contractor.ForEach(k => {
if (k == context.Customer){
k.Contacts.ForEach(cont => { //then get the list of contacts of this contractor
var item_b = new P_GetContactList_Contacts(); //for each contact in the list, create a block element
item_b.ContactName = cont; //and write the contact to the created element
context.Contacts.Add(item_b); //add the created element to the block
});
}
});