Solved

What can I use as a Custom Event trigger when the Internal Customer Order is created?

  • 22 April 2022
  • 6 replies
  • 584 views

Badge +4

Hello,       

        I’m looking to update the “PRIORITY” field of an Internal Customer Order from either the External Customer Order or better yet, the customer priority field found under Application Base Setup > Enterprise > Customer > Customer, then Order > Misc Customer Info tab.

      The problem with the Internal Customer Order not picking up the customer priority, is that it is from a different site (contract) than the External Customer Order.  We have all of our External Customer Orders set up for Site 0.  The Internal Customer Orders are set up for whatever site the order is being placed out of (Sites 13,14,16,18,19)

       As you may know, there is a delay when “Releasing” the External Customer Order, which the Purchasing Order is created, then the Internal Customer Order.  If you watch the Supply Chain Order Analysis screen after releasing an External Customer Order and constantly refresh it, you will eventually see the Internal Customer Order pop up.

         I am trying to write a custom event to get the priority and populate within the Internal Customer Order, similar to how that happens in the External Customer Order when it is created.  I’ve set up my custom event to trigger based on order release and made the custom event act as a background job, but it still fires before the Internal Customer Order is created, causing “ORA-20115: CustomerOrder.FND_REMOVED  The "Customer Order" has already been removed by another user.” error.  The custom event is below, any other ideas?

 

DECLARE
   attr_    VARCHAR2(32000);
   sql_msg_ VARCHAR2(32000);
   stmt_    VARCHAR2(32000);

BEGIN
   stmt_ := 'DECLARE
   info_ VARCHAR2(32000) := NULL;
   objid_ VARCHAR2(100) ;
   objversion_  VARCHAR2(100);
   attr_cf_ VARCHAR2(32000);
   attr_ VARCHAR2(32000) := '''';
   action_ VARCHAR2(32000) := ''DO'';
  order_no_    varchar2(35) := ''OLD:&ORDER_NO'';
  customer_no_ varchar2(35) := ''OLD:&CUSTOMER_NO'';
  priority_    varchar2(10);

cursor get_object IS
SELECT distinct INT.objid AS objid, INT.objversion AS objversion, INT.priority AS priority
FROM (
     SELECT soa.tree_id, col.order_no, col.objid, col.objversion, col.priority, col.customer_no
     FROM SUPPLY_ORDER_ANALYSIS soa
     INNER JOIN CUSTOMER_ORDER col ON soa.order_ref1 = col.order_no
     WHERE soa.CONTRACT <> 0
     ) INT,
     (SELECT soa.tree_id, col.order_no, col.objid, col.objversion, col.priority, col.customer_no
      FROM SUPPLY_ORDER_ANALYSIS soa
      INNER JOIN CUSTOMER_ORDER col ON soa.order_ref1 = col.order_no
      WHERE soa.CONTRACT = 0
     ) EXT
WHERE INT.TREE_ID = EXT.TREE_ID
AND EXT.order_no = order_no_;

BEGIN 
  open get_object; 
  fetch get_object into objid_, objversion_, priority_; 
  close get_object; 


  Client_SYS.Clear_Attr(attr_); 
  Client_SYS.Add_To_Attr(''PRIORITY'', CUST_ORD_CUSTOMER_API.Get_Priority(customer_no_ => customer_no_), attr_); 
  Customer_Order_API.Modify__(info_, objid_, objversion_, attr_, action_);

END;';

   sql_msg_ := Message_SYS.Construct('RELEASE');
   Message_SYS.Add_Attribute(sql_msg_, 'SQL', stmt_);

   Client_SYS.Clear_Attr(attr_);
   Client_SYS.Add_To_Attr('SQL_DATA_', sql_msg_, attr_);
   Client_SYS.Add_To_Attr('MSG_', '', attr_);

   Transaction_SYS.Deferred_Call('Fnd_Event_Action_API.Action_Executeonlinesql', 
                                 'PARAMETER', 
                                 attr_, 
                                 'Populate ICO priority with ECO priority.');
END; 

 

Thank you,

Mike

icon

Best answer by WMCMARSEGLIA 24 May 2022, 15:50

View original

6 replies

Userlevel 7
Badge +20

Hi @WMCMARSEGLIA ,

 

You could overcome the error of internal CO of not created while the time external CO is released by base the event on Incoming customer order and triggering when the Incoming CO is Created.

But in the incoming CO, you can only see the internal PO and need to find the external CO with one extra cursor. But looking at your script, pretty sure you’ll manage that :)

 

Cheers!

Damith

Badge +4

Hey Damith,

               Thank you very much for the response!  Yes, I am now trying to use the Customer_Order view and Customer_Order table on a custom event.  I am setting the custom event to be a background job that now work from when the Internal Custom Order is created and rowstate goes from != ‘released’ to ‘released’.  From the internal order, I also have the internal PO like you said, but I am having trouble getting back to the External Order from the API, but I keep running into the requirement of the PO LINE_NO and RELEASE_NO, which these fields are not contained in this Customer_Order event.

CUST_ORD_CUSTOMER_API.Get_Priority(customer_no_ => CUSTOMER_ORDER_API.Get_Customer_No(order_no_ => PURCHASE_ORDER_LINE_PART_API.Get_Demand_Order_No(order_no_ => &OLD:CUSTOMER_PO_NO,line_no_ => '1',release_no_ => '1')))

OR

CUSTOMER_ORDER_API.Get_Priority(order_no_ => PURCHASE_ORDER_LINE_PART_API.Get_Demand_Order_No(order_no_ => &OLD:CUSTOMER_PO_NO,line_no_ => '1',release_no_ => '1'))

 

         Would you happen to know another way?  Should I be using CUSTOMER_ORDER_LINE for an event LU?

 

Thank you for any help, very much appreciated,

Mike

Badge +4

Sorry, I meant CustomerOrder LU and Customer_Order_Tab.

 

How would you set this event to know if the order is Created?

Userlevel 7
Badge +20

Sorry, I meant CustomerOrder LU and Customer_Order_Tab.

 

How would you set this event to know if the order is Created?

 

Hi @WMCMARSEGLIA 

Can you post your modified event SQL?

How deep can your supply chain go? is it always external CO → Internal PO → Internal CO or can this go up in down to further levels?

 

Cheers!

Damith

Badge +4

Hey Damith, sure!  Unfortunately, it still seems to run as a background job before the internal customer order is created, once we release the external customer order, so it’s not catching the internal order, even if the priority update is working.  Still struggling with that.

We don’t use DOP (yet), so the supply chain depth looks like this: (other screenshots and code below also)

 

 

DECLARE
   attr_    VARCHAR2(32000);
   sql_msg_ VARCHAR2(32000);
   stmt_    VARCHAR2(32000);

BEGIN
   stmt_ := 'DECLARE
   info_ VARCHAR2(32000) := NULL;
   objid_ VARCHAR2(100) ;
   objversion_  VARCHAR2(100);
   attr_cf_ VARCHAR2(32000);
   attr_ VARCHAR2(32000) := '''';
   action_ VARCHAR2(32000) := ''DO'';
  order_no_    varchar2(35) := ''OLD:&ORDER_NO'';
  customer_no_ varchar2(35) := ''&OLD:CUSTOMER_NO'';
  internal_po_no_    varchar2(35) := ''&OLD:INTERNAL_PO_NO'';
  ico_priority_ varchar2(35) := ''&OLD:PRIORITY'';
  priority_ varchar2(35); 

cursor get_object IS
select objid, objversion, priority
  from customer_order
  where order_no = order_no_;

BEGIN
  open get_object; 
  fetch get_object into objid_, objversion_, priority_;
  close get_object;

if(ico_priority_ IS NULL) THEN
  Client_SYS.Clear_Attr(attr_); 
  Client_SYS.Add_To_Attr(''PRIORITY'', CUST_ORD_CUSTOMER_API.Get_Priority(customer_no_ => CUSTOMER_ORDER_API.Get_Customer_No(order_no_ => PURCHASE_ORDER_LINE_PART_API.Get_Demand_Order_No(order_no_ => internal_po_no_,line_no_ => ''1'',release_no_ => ''1''))), attr_); 
  Customer_Order_API.Modify__(info_, objid_, objversion_, attr_, action_);
end if;
END;';

   sql_msg_ := Message_SYS.Construct('RELEASE');
   Message_SYS.Add_Attribute(sql_msg_, 'SQL', stmt_);

   Client_SYS.Clear_Attr(attr_);
   Client_SYS.Add_To_Attr('SQL_DATA_', sql_msg_, attr_);
   Client_SYS.Add_To_Attr('MSG_', '', attr_);

   Transaction_SYS.Deferred_Call('Fnd_Event_Action_API.Action_Executeonlinesql', 
                                 'PARAMETER', 
                                 attr_, 
                                 'Populate ICO priority with ECO priority.');
END;

Badge +4

OK, I accomplished this by using a Customer_Order_Line LU and the Customer_Order_Line_Tab trigger when the order line on an Internal Customer Order (Contract !=0) rowstate becomes “Released”.  I just use the first line on the purchase order to find the External Customer No, then ultimately the priority from the customer record.  I check to see if that is NULL or not.

Here is the action:

NEW:CONTRACT != 0, OLD_ROWSTATE != Released, NEW_ROWSTATE = Released

DECLARE
   attr_    VARCHAR2(32000);
   sql_msg_ VARCHAR2(32000);
   stmt_    VARCHAR2(32000);
   
BEGIN
  stmt_ := 'DECLARE
  info_       varchar2(2000);
  objid_      varchar2(100);
  objversion_ varchar2(100);
  attr_    VARCHAR2(32000);
  action_     VARCHAR2(32000) := ''DO'';
  order_no_   varchar2(35) := ''&NEW:ORDER_NO'';
  order_po_no_ varchar2(35) := ''&NEW:DEMAND_ORDER_REF1'';
  
  cursor get_object IS
  select objid, objversion
  from customer_order
  where order_no = order_no_
  and state = ''Released'';

BEGIN 
  open get_object; 
  fetch get_object into objid_, objversion_; 
  close get_object; 

if(CUST_ORD_CUSTOMER_API.Get_Priority(customer_no_ => CUSTOMER_ORDER_API.Get_Customer_No(order_no_ => PURCHASE_ORDER_LINE_PART_API.Get_Demand_Order_No(order_no_ => order_po_no_,line_no_ => ''1'',release_no_ => ''1''))) IS NOT NULL) THEN
  Client_SYS.Clear_Attr(attr_); 
  Client_SYS.Add_To_Attr(''PRIORITY'', CUST_ORD_CUSTOMER_API.Get_Priority(customer_no_ => CUSTOMER_ORDER_API.Get_Customer_No(order_no_ => PURCHASE_ORDER_LINE_PART_API.Get_Demand_Order_No(order_no_ => order_po_no_,line_no_ => ''1'',release_no_ => ''1''))), attr_); 
  Customer_Order_API.Modify__(info_, objid_, objversion_, attr_, action_);
end if;
END;';

   sql_msg_ := Message_SYS.Construct('RELEASE');
   Message_SYS.Add_Attribute(sql_msg_, 'SQL', stmt_);

   Client_SYS.Clear_Attr(attr_);
   Client_SYS.Add_To_Attr('SQL_DATA_', sql_msg_, attr_);
   Client_SYS.Add_To_Attr('MSG_', '', attr_);

   Transaction_SYS.Deferred_Call('Fnd_Event_Action_API.Action_Executeonlinesql', 
                                 'PARAMETER', 
                                 attr_, 
                                 'Populate ICO priority with ECO priority.');
END;

 

Reply