Validation on New Opportunity

Hello,

We have a custom field named "Type of Customer" on the Company Entity, however, we would like it so that it is not possible to create new opportunities for companies with a specific type of customer. I have used the existing validation in place to stop Opportunities getting created where Company Type is Supplier, however, this isn't working and we can still make opportunities regardless of the Type of Customer.

Please see the validation below:

var company = eWare.FindRecord('Company', 'comp_primaryaccountid='+Values('oppo_primaryaccountid'));
if(company.comp_c_typeofcustomer=='Type A')
{
Valid = false;
ErrorStr="You cannot create an opportunity for a company with Type A";
};

This has been added to the 'Validate Script' for the oppo_primarycompanyid. I'm not sure on what I may be doing wrong as to why it isn't working, please does anyone have any suggestions?

CRM Version: Sage 200 CRM 2018 R3.3

Kind Regards,

Jamie

  • 0

    A simple method could be to go to Administration - Adv. Customisation - System Menus - New and under 'Opportunity' in the SQL field put in U:0

    This would remove the New Opportunity option from the New Menu

    Then on Companies suppress the Opportunity tab on certain record types. Users could still go to My/Team CRM and create new opportunities from there, but with training they could be guided to always go to the company first.... then create Opportunities from there.

    Also in your script you could change it to the following (JavaScript is my not strong point)

    var company = eWare.FindRecord('Company', 'comp_companyid='+Values('oppo_primarycompanyid'));

  • 0

    Use oppo_primarycompanyid. You could use the SQL filter on the tab but you'd need to add scripts in several places to stop them creating opportunities.

    This: if(company.comp_c_typeofcustomer=='Type A')

    You should be comparing the translation code which won't have a space in it. If the translation is Type A then the code might be TypeA but check in translations.