Provide Skeleton Logic Hook: Skeleton template to add sales pipeline date and duration tracking template #4540

Open
opened 2026-02-20 16:19:13 -05:00 by deekerman · 1 comment
Owner

Originally created by @vmw on GitHub (May 21, 2021).

There are a number of uses for tracking the amount of time an opportunity spends in each sales stage. This information can be used in reports, or to determine sales cycle times and also useful conversion information. This seems to be a feature request that comes up a couple of times.

This pull request provides a (commented out) logic hook that can be easily modified to support this kind of reporting. It also provides a starting point for implementing custom logic.

https://community.suitecrm.com/t/sales-workflow/37301

Issue

There are two issues here; there isn't any skeleton or example code for how to implement a custom logic hook. And, there isn't an easy way to keep track of how the amount of time an opportunity spends in each sales stage.

This issue resolves both, by providing a commented example of a logic hook, which users can subsequently modify to meet their own needs.

Expected Behavior

Ideally, there should exist a sample template or dummy code that people can use when first learning about logic hooks. This would provide a better entry and allow people to test and develop their own logic hook implementations.

Actual Behavior

There aren't really any examples of functioning logic hooks.

Possible Fix

Submitting a PR that provides this example code, along with reasonably inline comments.

Context

We spent around 3 weeks trying to implement this feature for our own uses. During this time, we found that this was a reasonably common use case on the forums, but that concrete and detailed instructions for exactly how to implement a logic hook weren't readily available.

Instead, we had to piece it together from a number of different sources.

This commit, provides an example of a (commented out) functioning logic hook, albeit one that would need to be modified to support the default sales stages. It needs to be modified to support the default sales stages, and also requires some fields to be added, but otherwise works.

Originally created by @vmw on GitHub (May 21, 2021). There are a number of uses for tracking the amount of time an opportunity spends in each sales stage. This information can be used in reports, or to determine sales cycle times and also useful conversion information. This seems to be a feature request that comes up a couple of times. This pull request provides a (commented out) logic hook that can be easily modified to support this kind of reporting. It also provides a starting point for implementing custom logic. https://community.suitecrm.com/t/sales-workflow/37301 #### Issue There are two issues here; there isn't any skeleton or example code for how to implement a custom logic hook. And, there isn't an easy way to keep track of how the amount of time an opportunity spends in each sales stage. This issue resolves both, by providing a commented example of a logic hook, which users can subsequently modify to meet their own needs. #### Expected Behavior Ideally, there should exist a sample template or dummy code that people can use when first learning about logic hooks. This would provide a better entry and allow people to test and develop their own logic hook implementations. #### Actual Behavior There aren't really any examples of functioning logic hooks. #### Possible Fix Submitting a PR that provides this example code, along with reasonably inline comments. #### Context We spent around 3 weeks trying to implement this feature for our own uses. During this time, we found that this was a reasonably common use case on the forums, but that concrete and detailed instructions for exactly how to implement a logic hook weren't readily available. Instead, we had to piece it together from a number of different sources. This commit, provides an example of a (commented out) functioning logic hook, albeit one that would need to be modified to support the default sales stages. It needs to be modified to support the default sales stages, and also requires some fields to be added, but otherwise works.
Author
Owner

@gwendo12 commented on GitHub (May 21, 2021):

Purpose

To update sales stage duration in the pipeline.

  • This update is used to track the amount of time an opportunity spends in each sales stage.
  • This information can be used in reports, or to determine sales cycle times and also useful conversion information.
  • The code is called with a before_save module hook from the logic hooks file in the Opportunities module folder.

Target Outcome

  • To keep track of the duration (time) spent in each stage,
  • To keep track of when it entered into each stage.

Files

  • logic_hooks.php: Line added with a before_save module hook in the Opportunities module folder.
  • SetOppDates.php: Code to calculation dates and durations for sales stages.

Fields

Last Sales Stage

  • Display Label: Last Sales Stage

  • Field Type: DropDown

  • Field Name: time_in_discovery_c

  • Description: Need to create one property per sales cycle stage, like, "time_in_discovery_c" to keep track of the amount of time it has been in that property. If the sales stage is changed, then find the difference between when it was set (DateTime {StageName} Set), and when it was changed (DateTime Last Modified {StageName}), and keep track of that.

DateTime {StageName} Set

  • Display Label: DateTime Discovery Set

  • Field Type: DateTime

  • Field Name: last_sales_stage_c

  • Description: Create a DropDown field to keep track of the last sales stage the opp was in.

Date Sales Stage Set

  • Display Label: Date Sales Stage Set

  • Field Type: DateTime

  • Field Name: sales_stage_date_set_c

  • Description: Create a DateTime field to keep track of the last time the sales stage time information was set.

Time in {StageName}

  • Display Label: Time in Discovery

  • Field Type: Integer

  • Field Name: time_in_discovery_c

  • Description: Need to create one property per sales cycle stage, like, "time_in_discovery_c" to keep track of the amount of time it has been in that property. If the sales stage is changed, then find the difference between when it was set (DateTime {StageName} Set), and when it was changed (DateTime Last Modified {StageName}), and keep track of that.

Implementation Notes

Keepstrack, globally, of the last time you updated the duration an opportunity has been in any particular stage (last mod- on creation, last mod should equal current date time). The difference between the last time you updated any sales stage duration time, and the current time, corresponds to the duration that you need to add to the current sales stage (if the sale stage hasn’t changed), or to the last sales stage (if this is being triggered when changing sales stage).

Step 1: When was the last time we updated any sales stage duration for that opportunity?

Step 2: What is the current time?

=>This provides us with the duration that we need to account for. That’s because the whole point of this logic is to account for the how much time is spent (since the op was first created) in each sales stage.

Given that each opportunity is always in a particular stage, we can just find the difference between the last time we updated a duration, and the current time. That’s the amount of time that has elapsed since we last updated any record, and corresponds to the amount of time we should account for.

This is largely because the total time that this opportunity is open should correspond to the sum of durations that it is in each sales stage.

@gwendo12 commented on GitHub (May 21, 2021): ## Purpose To update sales stage duration in the pipeline. * This update is used to track the amount of time an opportunity spends in each sales stage. * This information can be used in reports, or to determine sales cycle times and also useful conversion information. * The code is called with a before_save module hook from the logic hooks file in the Opportunities module folder. ## Target Outcome * To keep track of the duration (time) spent in each stage, * To keep track of when it entered into each stage. ## Files * logic_hooks.php: Line added with a before_save module hook in the Opportunities module folder. * SetOppDates.php: Code to calculation dates and durations for sales stages. ## Fields **Last Sales Stage** * Display Label: Last Sales Stage * Field Type: DropDown * Field Name: time_in_discovery_c * Description: Need to create one property per sales cycle stage, like, "time_in_discovery_c" to keep track of the amount of time it has been in that property. If the sales stage is changed, then find the difference between when it was set (DateTime {StageName} Set), and when it was changed (DateTime Last Modified {StageName}), and keep track of that. **DateTime {StageName} Set** * Display Label: DateTime Discovery Set * Field Type: DateTime * Field Name: last_sales_stage_c * Description: Create a DropDown field to keep track of the last sales stage the opp was in. **Date Sales Stage Set** * Display Label: Date Sales Stage Set * Field Type: DateTime * Field Name: sales_stage_date_set_c * Description: Create a DateTime field to keep track of the last time the sales stage time information was set. **Time in {StageName}** * Display Label: Time in Discovery * Field Type: Integer * Field Name: time_in_discovery_c * Description: Need to create one property per sales cycle stage, like, "time_in_discovery_c" to keep track of the amount of time it has been in that property. If the sales stage is changed, then find the difference between when it was set (DateTime {StageName} Set), and when it was changed (DateTime Last Modified {StageName}), and keep track of that. ## Implementation Notes Keepstrack, globally, of the last time you updated the duration an opportunity has been in any particular stage (last mod- on creation, last mod should equal current date time). The difference between the last time you updated any sales stage duration time, and the current time, corresponds to the duration that you need to add to the current sales stage (if the sale stage hasn’t changed), or to the last sales stage (if this is being triggered when changing sales stage). Step 1: When was the last time we updated any sales stage duration for that opportunity? Step 2: What is the current time? =>This provides us with the duration that we need to account for. That’s because the whole point of this logic is to account for the how much time is spent (since the op was first created) in each sales stage. Given that each opportunity is always in a particular stage, we can just find the difference between the last time we updated a duration, and the current time. That’s the amount of time that has elapsed since we last updated any record, and corresponds to the amount of time we should account for. This is largely because the total time that this opportunity is open should correspond to the sum of durations that it is in each sales stage.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SuiteCRM-SuiteCRM#4540
No description provided.