Since TaskRay is a 100% Salesforce native application, the Lightning Process Builder and Flow can be used to automate various TaskRay processes.
In this article we will be leveraging the "Stitch a TaskRay Project (Flow Only)" Apex Flow action. This Flow action can create or update a TaskRay Project with a dynamic set of Task Groups (previously created in templates). In this article, we will configure a Process Builder and Flow to create a TaskRay Project consisting of Task Groups related to Opportunity Products when an Opportunity's Stage changes to Closed Won.
As you go through these instructions, keep in mind that there are many other possibilities for customizing the process and you can modify the setup to suit the specific needs of your organization.
Step 1: Set Everything Up in TaskRay
The first step of the process is to make sure that you have all the necessary templates ready in TaskRay. You can learn more about creating templates here.
It is up to you how you want to keep the templates organized, but for this example, the first thing that you will need to do is make sure that you have a basic template project in TaskRay for customer onboarding, which will be used as a base template for the new project. This can either be an empty template project, or it can contain some generic onboarding tasks that will apply to all onboarding processes, regardless of the circumstances.
Next, create another template project called "Product Templates" which will contain Task Groups that are specific to the products and fulfillment services your company offers. If two products have the same steps to fulfill, you can simply relate one product template Task Group to two products. In our example we need to assign fulfillment Task Groups to these products:
In our case, the fulfillment of all the generators is the same with the exception of the "GenWatt Gasoline 2000kW". The SLA products will all use the same template Task Group from TaskRay. The installation Task Groups are all the same with exception of "Installation: Portable". So our list of template Task Groups to create will look like:
- Generic Generator Fulfillment
- GenWatt Gasoline 2000kW Fulfillment
- Generic Installation Fulfillment
- Installation Portable Fulfillment
- SLA Fulfillment
We'll create those now and add appropriate tasks to our "Product Template" project.
Step 2: Relate Task Groups to Products
Now that TaskRay is all set up and you have the template Task Groups created, the next step is to relate the template Task Groups you just created to the Products in Salesforce.
Create a New Field on Product
- From Setup, navigate to:
- Lightning: Objects and Fields | Object Manager. Select the Product object.
- Classic: Build | Customize | Products | Fields.
- Under Custom Fields and Relationships, click on New.
- Follow the steps to create a new Lookup Relationship field named "Template Task Group". On Step 2, for Related To, select TaskRay Task Group.
Now that we have a field to relate a Product to a TaskRay Task Group we can populate the field on our products with the Task Group Templates we created above. This is what ours looks like:
Create a New Field on Opportunity Products
This formula field is needed so that we can access the product's Task Group in Flow.
- From Setup, navigate to:
- Lightning: Objects and Fields | Object Manager. Select the Opportunity Product object.
- Classic: Build | Customize | Opportunity Products | Fields.
- Under Custom Fields and Relationships, click on New.
- On the New Custom Field setup page, select the following:
- Step 1: Select Formula.
- Step 2: Enter Field Label (e.g. "Task Group Template") and for formula return type select Text.
- Step 3: Configure the formula to point to the "Template Task Group" field we configured on the Product object. Do this by clicking on the Insert Field button and then following Opportunity Product > Price Book Entry > Product > Template Task Group. It should insert "PricebookEntry.Product2.Template_Task_Group__c" into your formula.
- Complete the rest of the field configuration as appropriate.
Step 3: Build the Flow
Now that we have our fields and templates created, we can start building the Flow which will stitch together our project. In general, this Flow will take in a few input variables from an Opportunity, look up what products are on the Opportunity, figure out what Task Groups should be in the Project, then clone a new Project consisting of our base customer onboarding template and additional Task Groups as defined by the Opportunity's products.
- From Setup, navigate to:Lightning: Process Automation | Flows.
- Classic: Create | Workflow & Approvals | Flows.
- Click New Flow.
- In the left sidebar, select the Manager tab, then click New Resource.
- For Resource Type, select Variable. Enter an API Name (e.g. "OpportunityId").
- For Data Type, select Text.
- Under Availability Outside the Flow, select Available for input.
- Create another Variable for OpportunityName.
- For Data Type, select Text.
- For Availability Outside the Flow, select Available for input
- Create another Variable for CloseDate.
- For Data Type, select Date
- For Availability Outside the Flow, select Available for input
- Create a Variable for templateProjectId.
- For Data Type, select Text.
- For Default Value, enter the Salesforce Record ID of your base template project.
- For Availability Outside the Flow, select Available for input.
- In the left sidebar, select the Elements tab. Under Data, select Get Records and drag it onto the canvas. Create a new Get Records element to find the Products for the OpportunityId variable we just defined.
- Select the Opportunity Product object and set the Condition Requirements to Conditions are Met.
- Configure the following conditions to ensure that only Opportunity Products with a defined TaskRay Task Group that are related to a given Opportunity are selected.
- OpportunityId Equals {!OpportunityId}
- Task_Group_Template__c Is Null {!$GlobalConstant.False}
- For How Many Record to Store, select All records.
- In the Select Variable to Store Opportunity Product Records section, create a new Resource. Configure the following settings.
- Resource Type: Variable
- Data Type: Record
- Allow multiple values (collection): True
- Object: Opportunity Product
- In the Select Opportunity Product Fields to Store in Variable section, add the Task_Group_Template__c formula field that was previously created.
- Back on the canvas, connect the elements by clicking the Start element and dragging the arrow to the Get Records element.
- Now, let's save our work for the first time. Click the Save button in the top-right corner of the canvas and name the Flow "Stitch Project on Opportunity Closed Won". For Type, select Autolaunched Flow.
- Next, create a few variables to keep track of what Task Groups we need to add to the Project.
- In the left sidebar, select the Manager tab, then click New Resource.
- Resource Type: Variable
- API Name: templateTaskGroupIdList
- Data Type: Text
- Allow multiple values (collection): True
- Create another New Resource
- Resource Type: Variable
- API Name: templateScheduleModeList
- Description: Variables can be "Start", "End", or a Milestone Id
- Data Type: Text
- Allow multiple values (collection): True
- Create another New Resource
- Resource Type: Variable
- API Name: templateTaskGroupTargetDateList
- Data Type: Date
- Allow multiple values (collection): True
- In the left sidebar, select the Manager tab, then click New Resource.
- In the Elements tab of the left sidebar, select the Loop element and drag it onto the canvas. Configure the loop:
- Label: Iterate Opportunity Products
- Collection Variable: {!OpportunityProducts}
- Direction: First item to last item
- Create a Loop Variable:
- Resource Type: Variable
- API Name: OpportunityProduct
- Data Type: Record
- Allow multiple values (collection): False
- Object: Opportunity Product
- Save and then connect the Get Records and Loop elements on the canvas.
- In the Elements tab in the left sidebar, select the Assignment element and drag it onto the canvas. Configure the Assignment to set the following variable values:
- Label: Assign Task Group Lists
- Variable Values:
- Variable: Collection Variables | templateTaskGroupIdList
- Operator: Add
- Value: Record Variables | Opportunity Product | Task_Group_Template__c
- Variable: Collection Variables | templateTaskGroupTargetDateList
- Operator: Add
- Value: Variables | CloseDate
- Variable: Collection Variables | templateScheduleModeList
- Operator: Add
- Value: Start
-
-
- Click Done, then connect the Loop element with the new Assignment element as shown below:
- In the Elements tab in the left sidebar, select the Apex Action element and drag it onto the canvas. Configure the action:
- Action Type: Apex Action
- Apex Action: Stitch a TaskRay Project (Flow Only)
- Label: Stitch a Project
- Set Input Values:
- New Project: Global Constants | $GlobalConstant.True
- New Project Date Target: Variables | CloseDate
- New Project Name: Variables | OpportunityName
- New Project Schedule Mode: Start
- New Project Template Id: Variables | templateProjectId
- Source Object Id: Variables | OpportunityId
- Task Group Id List: Collection Variables | templateTaskGroupIdList
- Task Group Schedule Mode List: Collection Variables | templateScheduleModeList
- Task Group Target Date List: Collection Variables | templateTaskGroupTargetDateList
- Click Done, then connect the Loop element with the new Apex Action:
- Save and Activate your Flow.
-
Step 4: Build the Process to Execute the Flow
Now that we have a Flow in place, we can use Process Builder to execute the Flow. In general, this Process will run when an Opportunity's Stage is set to Closed Won and pass a few input variables to the Flow.
Create a New Process
- From Setup, navigate to:
- Lightning: Process Automation | Process Builder
- Classic: Create | Workflow & Approvals | Process Builder
- Click New.
- Enter the Process Name, API Name, and Description.
- For The process starts when field, select A record changes.
- Click Save.
Select the Object for the Process
First, select the object that will trigger the automated process. In this case, we will select the Opportunity object, because that's where the initial action will take place.
- On the canvas, click + Add Object.
- For the Object, select Opportunity.
- Under Start the process, select when a record is created or edited.
- Click Save.
Define the Criteria That Triggers the Process
Next, define the criteria that will trigger the process. In our example, it would be the act of changing the Stage of an Opportunity to Closed Won.
- On the canvas, click +Add Criteria.
- Enter the Criteria Name.
- Under Criteria for Executing Actions, select Conditions are met.
- Under Set Conditions, select the following:
- Field = [Opportunity] Stage
- Operator = Equals
- Type = Picklist
- Value = Closed Won
- Under Conditions, select All of the conditions are met (AND).
- Click Advanced to expand additional settings and select the Yes checkbox.
- This will ensure that the process only executes when the specified changes are made to the record. In this case, that's only when an Opportunity Stage is changed from another value to Closed Won.
- Click Save.
Define the Action That Occurs When the Process Runs
Finally, define the action that should occur when the process executes. In our example, we'll launch the Flow that we previously created and pass it a few input variables.
- On the canvas under Immediate Actions, click +Add Action.
- For Action Type, select Flows.
- Enter the Action Name.
- For Flow, select Stitch Project on Opportunity Closed Won.
- Set the following Flow Variables:
- Flow Variable: OpportunityId
- Type: Field Reference
- Value: [Opportunity] Opportunity ID
- Flow Variable: CloseDate
- Type: Field Reference
- Value: [Opportunity] Close Date
- Flow Variable: OpportunityName
- Type: Field Reference
- Value: [Opportunity] Name
- Save, then click Activate in the top-right corner.