Skip to main content

i would like to set some default values on customer order screen based on site and customer, if the customer is ‘A’ and site is ‘1’ the defauct value for market code should be ‘X’ , else if the customer is ‘A’ and site is ‘2’ the default value of market code should be ‘Y’, tried writing a custom event using before insert but its giving error.

the code

if('&NEW:CUSTOMER_NO' IN ('CE01') and '&NEW:CONTRACT' IN ('CME02'))
THEN
'&NEW:DISTRICT_CODE' = 'LB002'
ENDIF;

Hi @m.arif 

It’s helpful if you could upload the error message but you may find some points here.

Above code does not assign a new vale to DISTRICT_CODE. Instead you have to add the value to Attribute String and then call the Modify method. However this too will end up giving the mutating error.

Solution

  1. Create the customer order with its default District Code.
  2. Create a custom event to trigger when inserting a new record to CUSTOMER_ORDER_TAB. Event Action of this will modify the DISTRICT_CODE based on your conditions.
  3. Create another custom event to call above custom event in step 2 in background to avoid mutating error.

Once the background job is successfully finished, the new District Code will appear in the customer order.

Step 2 custom event example

 

 

Step 3 custom event example

 

 

The disadvantage here is you have to wait until the background job finishes, to see the updated District Code. 

There are other alternatives, but depend on your requirement.

  • Update the District Code using a custom menu
  • You can create a custom field if the value is only for display purposes (i.e. if DISTRICT_CODE in CUSTOMER_ORDER_TAB is not necessary to be updated)