Print this page

Sample Flow to copy child Records from one object to another, and update the original items.

Knowledge Article Number 000214041
Description The use case, for example, you have an Object Project, which has Line Items of LoggedHours, and you want to copy these as BilledHours to an Invoice object.

The Flow is called with a Button, we have to pass the ProjectID

Steps that are taken in this Flow:
  • Set a variable through a Record Lookup to reference the Invoice related to the Project
  • Copy those Line Items (Logged Hours) that are not billed yet and are billable to an SObject Collection Variable (CollLoggedHours)
  • Loop through each individual Record of the Line Items
    • Line Item is copied to the new object type (BilledHours)
    • add the new Line Item to a collection (CollBilledHours)
    • update the original Line Item as billed (LoggedHours)
    • add the updated Line Item to a new collection (CollLoggedHoursUpdated)
  • Create the new Line Items (CollBilledHours)
  • Update the originals Line Items (CollLoggedHoursUpdated)


Prerequisites:
  • Object Invoice
  • Object BilledHours, which is the Detail of a Master Detail relation ship with Invoice
  • Object Project, with a lookup to Object Invoice
  • Object LoggedHours, which is the Detail of a Master Detail relation ship with Project

Two fields on LoggedHours, both check-boxes:
  • Billable
  • Billed

Other fields:
  • On Object BilledHours, a Lookup to LoggedHours, to reference what was billed
Resolution First step to create the following variables, all with Input/Output type: Input and Output
  • Variable: Name: ProjectID; Data Type: Text
  • Variable: Name: InvoiceForThisProject; Data Type: Text
  • SObject Variable: Name: indBilledHours; object Type: BilledHours__c
  • SObject Variable: Name: indLoggedHours; object Type: LoggedHours__c
  • SObject Collection Variable: Name: CollLoggedHours; object Type: LoggedHours__c
  • SObject Collection Variable: Name: CollLoggedHoursUpdated; object Type: LoggedHours__c
  • SObject Collection Variable: Name: CollBilledHours; object Type: BilledHours__c

Next step, the Elements:
Copy Logged Hours From Project To Invoice
Record Lookup
Name: lookup Invoice For This Project
Lookup: Project__c
Meets criteria:
Id equals ProjectID
Assign Field:
Invoice__c to InvoiceForThisProject

This Element needs to be set as the start Element

Fast Lookup
Name: lookup CollLoggedHours for this Project
Lookup: LoggedHours__c
Meets criteria:
Billable__c equals {!$GlobalConstant.True}
Billed__c equals {!$GlobalConstant.False}
Project__c equals {!ProjectID}
Variable: {!CollLoggedHours}
Fields to save:
Billable__c
Billed__c
Hours__c
Project__c
Id
Name


Loop
Name: loop Through LoggedHours
Loop through: {!CollLoggedHours}
Loop Variable: {!IndLoggedHours}


Assignment
Name: Copy LoggedHours To BilledHours and set Invoice ID
Variable:
{!IndBilledHours.Hours__c} equals {!IndLoggedHours.Hours__c}
{!IndBilledHours.Invoice__c} equals {!InvoiceForThisProject}
{!IndBilledHours.Name} equals {!IndLoggedHours.Name}


Assignment
Name: Add indBilledHours to CollBilledHours
Variable:
{!CollBilledHours} add {!IndBilledHours}


Assignment
Name: Set indLoggedHours Billed to True
Variable:
{!IndLoggedHours.Billed__c} equals {!$GlobalConstant.True}


Assignment
Name: Add IndLoggedHours to CollLoggedHoursUpdated
Variable:
{!CollLoggedHoursUpdated} equals {!IndLoggedHours}


Fast Create
Name: create CollBilledHours
Variable:
{!CollBilledHours}


Fast Create
Name: update CollLoggedHoursUpdated
Variable:
{!CollLoggedHoursUpdated}

The connections between these should go from:
lookup Invoice For This Project to
lookup CollLoggedHours for this Project to
loop Through LoggedHours to (Next Element)
Copy LoggedHours To BilledHours and set Invoice ID to
Add indBilledHours to CollBilledHours to
Set indLoggedHours Billed to True to
Add IndLoggedHours to CollLoggedHoursUpdated to
loop Through LoggedHours to
create CollBilledHours to
update CollLoggedHoursUpdated
 




promote demote