Issue With Trigger

Hi,

I have created a field Customer Code in customer doctype. Each time a customer of customer type “Company” is created, The field customer_code must be incremented by 1.

However, each time a customer is created, the customer code is being increment and not only when the customer type is “Company”.

I am also getting the following error mesages "PyMsql.err.InternalError:(1054,“Unknown column ‘tabServiceLevelAgreement.Customer’ in’whereclause’”)

Below is the Trigger Script.

Has anyone encountered this issue before or can assist?

CREATE OR REPLACE TRIGGER tab_Customer_before_insert
BEFORE INSERT ON lbd3e0294da19198.tabCustomer
FOR EACH ROW
BEGIN
DECLARE ref_code int;
SELECT max(customer_code)+1 INTO ref_code
FROM lbd3e0294da19198.tabCustomer
WHERE customer_type =‘Company’;
SET NEW.customer_code =ref_code;
END
/

Thanks

Are you not missing an if in your sql trigger? Something like:


  IF NEW.customer_type = ‘Company’ THEN BEGIN
    SET NEW.customer_code =ref_code;
  END; END IF;