+ Start a Discussion
Laura Babb 4Laura Babb 4 

add priorvalue with new value being updated from process builder

I have a field that on Opportunity Product object (Quantity Used) that I update via process builder using a field reference to a field on a custom object (Quantity Used). The field update on Opp Product is then used to formulate the Quantity Remaining by subtracting the Quantity Used from the Quantity sold on the line item. The issue I'm having is that it obviously overwrites each time instead of adding the prior value of Quantity Used with the new amount to formulate the true number of used and remaining. Please tell me there is a way to accomplish what I need! TIA, developers!
Andrew GAndrew G
Reading your question, i'm a little confused, but I think the key question is:
The custom object,(Quantity Used), is it a many to one relation to the Oppty Product Object?  and that is where the problem lies?  i.e. the first Qty Used Record is created and updates the field correctly and then when the second Qty Used record is created, it overwrites the value rather than updating?

If that is what you are chasing, then you "could" use process builder, but I would be wary of the results.
Update the Process builder on the Quantiy Used Object to use the ISNEW() and then update the field on the related Oppty Product record using a formula like PRIORVALUE([OpportunityProduct].QuantityUsed__c) + [QuantityUsed].QuantityUsed__c

Then your field Quantity Remaining can be a formula field subtracting the other fields, and would not need an additional DML activity to update.

Note, with the above, the Opportunity Product field Quantity Used would need to have a default value of zero, (adding to blank fields doesn;t always work).

Note, I would be wary of the Process Builder option above because it would not recalculate if any of the Quantity Used records are deleted.  Hence, a trigger would be more robust.

Hope the above is helpful


Laura Babb 4Laura Babb 4
Hi Andrew, Yes, essentially that is what I’m trying to do. Specifically, the custom object is Data Feasibility Request and it is related to the Opportunity object. Example: Opportunity has line item for Data Cleanse product with a 5,000 quantity sold. Data Feasibility Request is a custom object used to track Data job requests/performed internally. If the data team inputs 3,000 in the Quantity Used field on Data Feasibility Request, the process builder updates the Quantity Used field on the line item. That would then calculate 2,000 Quantity Remaining on the line item. I am trying to solve for what happens when more is used from the remaining 2,000. Currently, it overwrites the Quantity Used because it does not add the prior value with the next Data Feasibility record. This is confusing to explain, but it sounds like you get what I’m trying to accomplish. Unfortunately, I am not apex trigger savvy. Any way you could point me in the right direction for nailing this down? All help is appreciated! Thanks, Laura Laura Babb | SalesForce System Analyst | Televerde 4636 E. University Dr., Phoenix, AZ USA 85034 Direct 480-771-6727 | Main 480-771-6700 Follow Us: LinkedIn | Twitter | Blog | Televerde.com [cid:image001.png@01D4B3C2.1D0A7940] [cid:image004.jpg@01D50437.4B67BDA0]
Andrew GAndrew G
So the data model is:
Oppty Product is a lookup to Opportunity.
Data Feasibility Request (DFR) is (lookup) related to the Opportunity.
And there is a link between the DFR and the Oppty Product (probably a lookup).?

IF there is only ever one DFR, then it is OK for the process builder to overwrite the value of Quantity Used on the Oppty Product.
Make your Quantity Remaining  field on the Oppty Product a formula field (Quantity Sold - Quantity Used). (don't use a process builder to update the Quantity Remaining field as that complicates things).

IF there are multiple DFR, then update the Process builder on DFR to use ISNEW() in the criteria, and set the IA to update the related Object (Oppty Product).  And the field Quantity Used to be a formula as noted above:
PRIORVALUE([OpportunityProduct].QuantityUsed__c) + [DataFeasibilityRequest].QuantityUsed__c
Ensure the number field QuantityUsed__c on Oppty Product has a default value of zero.

IF there is only ever one DFR but you would like the Quantity Used field or the Quantity Remaining field on the Oppty Product to be directly editable, then we need to rethink things.

Hope that makes sense
Laura Babb 4Laura Babb 4
I figured out my issue… The oppty product is not available to create a lookup on from the DFR object. I have a lookup to the Product object, not Oppty Product, but I need it on the line item. Shoot! Laura Babb | SalesForce System Analyst | Televerde 4636 E. University Dr., Phoenix, AZ USA 85034 Direct 480-771-6727 | Main 480-771-6700 Follow Us: LinkedIn | Twitter | Blog | Televerde.com [cid:image001.png@01D4B3C2.1D0A7940] [cid:image004.jpg@01D50450.90B3E0A0]