function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Puja Dev 6Puja Dev 6 

How to copy value of currency field into "Unit Price" field of "OrderLine Item"...?

Hi,

I want to copy value of "discounted box price(Currency field)" in to the standard field "Unit Price" of OrderLineItem Object.
I have tryed using Workflow rule. Its working but it can not fullfill my requirment. So,I want trigger to copy "discounted box price" to "Unit Price".
Please let me know the solution.

Thanks, in advanced.
Puja
Amit Singh 1Amit Singh 1
If WFR is not fulfilling your requirement then write a trigger on OrderLineItem which will do the logic.
 
trigger OrderItem_Trigger on OrderItem (before insert) {
    for(OrderItem item : Trigger.New){
        item.UnitPrice = item.CustomField__c;
    }
}
Let me know if this helps.
 
Puja Dev 6Puja Dev 6
Hi Amit,

I want to update same for all records in orderitem of same order. at the time of every new item insertion.
 
Puja Dev 6Puja Dev 6
No, It's not working...
 
Puja Dev 6Puja Dev 6
:(
 
Amit Singh 1Amit Singh 1
Sorry My falut I forgot to make the Update. Use below code.
trigger OrderItem_Trigger on OrderItem (before insert) {
	List<OrderItem> orderItemList = [Select Id, UnitPrice, CustomField__c From Order Item LIMIT 50000];
	OrderItem orderItm = Trigger.New[0];
    for(OrderItem item : orderItemList){
        item.UnitPrice = orderItm.CustomField__c;
    }
update orderItemList;
}

 
Varun SinghVarun Singh

HI @puja

Please try this trigger please update your custom filed if it is differnt
 
trigger UpdateUnitPrice on OrderItem (before Insert, before Update) {

    for (OrderLineItem oppty : trigger.new) {
        
        //check if discounted_box_price__c have amount greater than zero
        if( oppty.discounted_box_price__c!= null && oppty.discounted_box_price__c> 0) {  
            
            //assign discounted_box_price__c fields value to unit price
            oppty.unitprice= oppty.discounted_box_price__c;           
        }
       
    }
}