Owns lead-management business logic that sits above the raw Lead and Task entities: team and task statistics for dashboards, lead and note creation, lead search and ranking, task and calendar notifications, and lookup or creation of the sales/leads groups and organisation types used to configure the leadman app for a tenant. Reached from Java and templates via the request context as LeadmanService, and marked Safe so it can also be invoked from sandboxed contexts.
Properties
| Property | Returns | Description |
|---|---|---|
| enableNewCompanyId | boolean | Whether the leadman app is configured to use the newer company id scheme, for the current tenant organisation. |
| leadsGroup | Group | The group that leads are added to as members, for the current tenant organisation. Creates the group if it does not already exist, using the configured "leadsGroup" name or "leads" if none is configured. |
| leadsOrgType | OrgType | The organisation type used to mark lead organisations, for the current root folder's organisation. The configured value is looked up first by name and, for legacy configuration, falls back to treating it as an organisation type id. |
| salesOrgType | OrgType | The organisation type used to mark sales organisations, for the current root folder's branch or organisation. The configured value is looked up first by name and, for legacy configuration, falls back to treating it as an organisation type id. |
Methods
cancelTask(Task t) · teamTaskStatus(Profile p, Organisation adminOrg) · teamStats(Profile p, Organisation adminOrg) · taskStats(Profile currentUser) · createNote(Task task, String newNote, String actionType, boolean inbound, Date now, Profile curUser) · createNote(Lead lead, String newNote, String actionType, boolean inbound, Date now, Profile curUser) · findTasksByDueDate(int numDays) · findTasksByDueDate(Profile p, int numDays) · assignedTags(Profile p) · removeTask(Task t) · getSalesManagerOrgs(Profile currentUser, Organisation rootOrg) · updateTask(Task t) · fireTaskAssignmentChanged(Task t, Profile previousAssignee) · doLeadSearch(String fieldType, List<String> fieldNames, String queryString, List<String> teams, List<Long> filterGroups, List<String> sourcesFilter, List<String> assignedToFilter, List<String> funnelsFilter, Integer from, Integer size) · doLeadSearch(String fieldType, List<String> fieldNames, String queryString, List<String> teams, List<Long> filterGroups, List<String> sourcesFilter, List<String> assignedToFilter, List<String> funnelsFilter, List<String> stagesCriteria, Integer from, Integer size) · searchLeadsRanked() · searchLeadsRanked(Profile assignedTo, int start, int size) · searchLeadsRanked(Funnel funnel) · searchLeadsRanked(LeadSearchCriteria crit, SearchProperties searchProperties) · softDelete(Lead lead, Organisation org) · softDelete(Lead lead, Organisation org, Profile deletedBy) · hardDelete(Lead lead, Organisation org) · deleteLeadCompany(Organisation org) · removeLeadsForStage(FunnelRepository funnel, Branch version, String stageName, Organisation org) · getEngagementScore(Funnel funnel, Lead lead) · isEnableNewCompanyId() · appendNotes(List<StreamEventBean> list, List<LeadNote> notes) · getLeadsGroup() · getLeadProfileExtraFields(Profile profile) · getSalesOrgType() · getLeadsOrgType()
cancelTask(Task t)
Returns: void
Cancels a task, recording the current time as its cancellation date.
| Parameter | Description |
|---|---|
t | the task to cancel |
teamTaskStatus(Profile p, Organisation adminOrg)
Returns: TaskStats
Calculates task completion statistics for the sales teams that the given profile manages, over the last 30 days. Searches the task index for tasks completed in that window and assigned to any organisation the profile manages as a sales manager, and counts how many were completed by their due date and how many were cancelled.
| Parameter | Description |
|---|---|
p | the sales manager whose managed teams' tasks are aggregated |
adminOrg | the tenant admin organisation to search within |
teamStats(Profile p, Organisation adminOrg)
Returns: TeamStats
Calculates lead and deal statistics for the sales teams that the given profile manages: the count and pipeline value of currently active leads, the count and value of deals closed in the last 30 days, and the number of tasks due within the next 7 days. Requires the profile to hold the sales manager role.
| Parameter | Description |
|---|---|
p | the sales manager whose managed teams' leads and deals are aggregated |
adminOrg | the tenant admin organisation to search within |
taskStats(Profile currentUser)
Returns: TaskStats
Calculates task completion statistics for tasks assigned to the given profile and completed so far this calendar year: how many were completed by their due date, the total completed, and how many were cancelled.
| Parameter | Description |
|---|---|
currentUser | the profile whose completed tasks are aggregated |
createNote(Task task, String newNote, String actionType, boolean inbound, Date now, Profile curUser)
Returns: LeadNote
Creates and persists a note against the given task, recording who made it and whether it represents inbound or outbound communication.
| Parameter | Description |
|---|---|
task | the task the note is attached to |
newNote | the note text |
actionType | the type of action the note records, used for timeline display and grouping |
inbound | true if the note represents communication received from the customer, false if sent to them |
now | the time the note was created |
curUser | the profile that created the note |
createNote(Lead lead, String newNote, String actionType, boolean inbound, Date now, Profile curUser)
Returns: LeadNote
Creates and persists a note against the given lead, recording who made it and whether it represents inbound or outbound communication.
| Parameter | Description |
|---|---|
lead | the lead the note is attached to |
newNote | the note text |
actionType | the type of action the note records, used for timeline display and grouping |
inbound | true if the note represents communication received from the customer, false if sent to them |
now | the time the note was created |
curUser | the profile that created the note |
findTasksByDueDate(int numDays)
Returns: List<Task>
Finds tasks due within the given number of days from now that are assigned to the current signed-in user.
| Parameter | Description |
|---|---|
numDays | the number of days from now to search up to |
findTasksByDueDate(Profile p, int numDays)
Returns: List<Task>
Finds tasks due within the given number of days from now that are assigned to the given profile, within the current tenant's admin organisation.
| Parameter | Description |
|---|---|
p | the profile whose due tasks are searched for |
numDays | the number of days from now to search up to |
assignedTags(Profile p)
Returns: List<Group>
Finds the mailing-list groups the given profile belongs to within the current tenant organisation. Used to show or manage which tag groups a lead's profile is subscribed to.
| Parameter | Description |
|---|---|
p | the profile whose tag group memberships are looked up, may be null |
removeTask(Task t)
Returns: void
Notifies the search index that a task has been removed, so it is dropped from search results. Has no effect if the task is null.
| Parameter | Description |
|---|---|
t | the task that was removed |
getSalesManagerOrgs(Profile currentUser, Organisation rootOrg)
Returns: List<Organisation>
Finds the organisations, within rootOrg, for which the given profile holds the sales manager role. Scans the profile's group memberships for group roles granting the sales manager role and keeps only those within rootOrg.
| Parameter | Description |
|---|---|
currentUser | the profile whose sales manager group memberships are scanned |
rootOrg | the organisation to restrict results to |
updateTask(Task t)
Returns: void
Applies the side effects of a task change: runs notification and calendar-event checks, and notifies the search index that the task was updated. Has no effect if the task is null.
| Parameter | Description |
|---|---|
t | the task that was updated |
fireTaskAssignmentChanged(Task t, Profile previousAssignee)
Returns: void
Fires a TaskAssigneeChangedEvent for the given task, recording who it was previously assigned to. Has no effect if the task is null.
| Parameter | Description |
|---|---|
t | the task whose assignment changed |
previousAssignee | the profile the task was previously assigned to, may be null |
doLeadSearch(String fieldType, List<String> fieldNames, String queryString, List<String> teams, List<Long> filterGroups, List<String> sourcesFilter, List<String> assignedToFilter, List<String> funnelsFilter, Integer from, Integer size)
Returns: KSearchResponse
Searches leads matching the given filter criteria, paged by from and size.
| Parameter | Description |
|---|---|
fieldType | the lead field type being searched |
fieldNames | the field names to search within |
queryString | the free-text search string, may be blank |
teams | team names to filter by |
filterGroups | group ids to filter by |
sourcesFilter | lead source names to filter by |
assignedToFilter | assignee identifiers to filter by |
funnelsFilter | funnel names to filter by |
from | the zero-based offset of the first result to return |
size | the maximum number of results to return |
doLeadSearch(String fieldType, List<String> fieldNames, String queryString, List<String> teams, List<Long> filterGroups, List<String> sourcesFilter, List<String> assignedToFilter, List<String> funnelsFilter, List<String> stagesCriteria, Integer from, Integer size)
Returns: KSearchResponse
Searches leads matching the given filter criteria, including funnel stage criteria, paged by from and size.
| Parameter | Description |
|---|---|
fieldType | the lead field type being searched |
fieldNames | the field names to search within |
queryString | the free-text search string, may be blank |
teams | team names to filter by |
filterGroups | group ids to filter by |
sourcesFilter | lead source names to filter by |
assignedToFilter | assignee identifiers to filter by |
funnelsFilter | funnel names to filter by |
stagesCriteria | funnel stage names to filter by |
from | the zero-based offset of the first result to return |
size | the maximum number of results to return |
searchLeadsRanked()
Returns: KSearchResponse
Searches all leads with a match-all query. Intended as a base for lead ranking, though score boosting is not yet applied.
searchLeadsRanked(Profile assignedTo, int start, int size)
Returns: List<LeadRankedBean>
Searches open leads (those without a closedDate) and ranks results so leads assigned to the given profile, or with an active task assigned to them, are boosted above other results.
| Parameter | Description |
|---|---|
assignedTo | the profile whose leads and active tasks are boosted in the ranking, may be null |
start | the number of leading results to skip |
size | the maximum number of results to return |
searchLeadsRanked(Funnel funnel)
Returns: KSearchResponse
Searches leads within the given funnel.
| Parameter | Description |
|---|---|
funnel | the funnel to search within |
searchLeadsRanked(LeadSearchCriteria crit, SearchProperties searchProperties)
Returns: KSearchResponse
Searches leads matching the given criteria: funnel, optional group, optional current funnel node, created date range and status (active, cancelled or closed). Results are paged and sorted according to searchProperties when given.
| Parameter | Description |
|---|---|
crit | the funnel and filter criteria to search by; must have a funnel set |
searchProperties | paging and sort order to apply, may be null to use default paging |
softDelete(Lead lead, Organisation org)
Returns: void
Soft-deletes a lead, attributing the deletion to the current signed-in user, and updates the tasks and search index that reference it.
| Parameter | Description |
|---|---|
lead | the lead to delete |
org | the organisation the deletion event is raised against |
softDelete(Lead lead, Organisation org, Profile deletedBy)
Returns: void
Soft-deletes a lead, attributing the deletion to the given profile, and updates the tasks and search index that reference it.
| Parameter | Description |
|---|---|
lead | the lead to delete |
org | the organisation the deletion event is raised against |
deletedBy | the profile the deletion is attributed to, may be null |
hardDelete(Lead lead, Organisation org)
Returns: void
Deletes a lead without attributing the deletion to any profile, and updates the tasks and search index that reference it.
| Parameter | Description |
|---|---|
lead | the lead to delete |
org | the organisation the deletion event is raised against |
deleteLeadCompany(Organisation org)
Returns: void
Soft-deletes an organisation that was used as a lead company: unlinks it from any leads that reference it as their company or assignee, removes all group memberships within it, and soft-deletes the organisation itself.
| Parameter | Description |
|---|---|
org | the organisation to unlink and soft-delete |
removeLeadsForStage(FunnelRepository funnel, Branch version, String stageName, Organisation org)
Returns: void
Clears the stage name from every lead currently at the given funnel stage, run within its own transaction. Used when a stage is removed from a funnel definition so existing leads are not left pointing at it.
| Parameter | Description |
|---|---|
funnel | the funnel repository the stage belongs to |
version | the funnel version (branch) to search leads within |
stageName | the name of the stage being removed |
org | the organisation to search leads within |
getEngagementScore(Funnel funnel, Lead lead)
Returns: Float
The lead's engagement score, converted from the double stored on the lead entity to a float for display. The funnel parameter is currently unused.
| Parameter | Description |
|---|---|
funnel | unused |
lead | the lead whose engagement score is read |
isEnableNewCompanyId()
Returns: boolean
Whether the leadman app is configured to use the newer company id scheme, for the current tenant organisation.
appendNotes(List<StreamEventBean> list, List<LeadNote> notes)
Returns: void
Converts lead notes into timeline stream event beans and appends them to the given list, for display on an activity timeline. Each note's title is taken from the matching customer action on its funnel where one is defined, otherwise from the note's own timeline title, and its category (danger, success or info) is derived from its action type.
| Parameter | Description |
|---|---|
list | the list that converted stream event beans are appended to |
notes | the lead notes to convert and append |
getLeadsGroup()
Returns: Group
The group that leads are added to as members, for the current tenant organisation. Creates the group if it does not already exist, using the configured "leadsGroup" name or "leads" if none is configured.
getLeadProfileExtraFields(Profile profile)
Returns: Map<ExtraField,String>
Builds the map of extra profile fields, and their current values, defined on the primary group memberships of the given profile. Excludes file-upload fields, and where the same field name appears on more than one membership only the required definition (or the first found) is kept.
| Parameter | Description |
|---|---|
profile | the profile whose extra fields are collected, may be null |
getSalesOrgType()
Returns: OrgType
The organisation type used to mark sales organisations, for the current root folder's branch or organisation. The configured value is looked up first by name and, for legacy configuration, falls back to treating it as an organisation type id.
getLeadsOrgType()
Returns: OrgType
The organisation type used to mark lead organisations, for the current root folder's organisation. The configured value is looked up first by name and, for legacy configuration, falls back to treating it as an organisation type id.