How to make the phone number and Email mandatory while creating a company

SOLVED

Hi All,

How to make the phone number and Email mandatory while creating a company?

Base on some post in the community, I tried to add a table script level checking as below.

if (!FormValues("fieldname"))

{

Valid = false;

ErrorStr = "Field must have a value";

}

But I'm getting the warning message only after company creation even though I added this script in 'Creat Script'. The company is created successfully, then showing this error message. Don 't know am I missing something.

Any help?

Parents
  • 0
    SUGGESTED
    • You do this in the validate script because you want to validate the fields before you save not on creation 
  • 0 in reply to Vega

    Hi ,

    Whrere can I add a validation script? When creating a company, email and phone fields are not available in customize screen as shown in the screenshot below.

    I tried to add from Email secondary entity screen, but that is also not working.

  • 0 in reply to Sulfath Shajahan
    SUGGESTED

    Hi

    The link is unavailable so here is a Table Level Script that is working in Sage 2024 r2.

    Found on a Greytrix post (https://www.greytrix.com/blogs/sagecrm/2021/02/25/mandate-companys-phone-and-email-address-using-table-level-script/)

    Go to Administration -> Customizing -> Compan -> Table Level Script -> Create new

    1. Type in a name

    2. Choose script type Entity level with rollback and copy in the following script for E-Mail and Phone

    EMAIL

    function emailvalidation (x,y)
    {
    if (x.length>0)
    {
    apos=x.indexOf("@");
    dotpos=x.lastIndexOf(".");
    lastpos=x.length-1;
    if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos <2)
    {
    Valid = false;
    ErrorStr = CRM.GetTrans("colnames",y)+ " ["+x+"] " + CRM.GetTrans("GenCaptions","BadMailAddress");
    }
    }
    else if(y=="emai_emailaddressbusiness")
    {
    Valid = false;
    ErrorStr = "Geschäftliche E-Mail Adresse nicht angegeben";}
    }
    function InsertRecord ()

    {

    // Handle insert record actions here
    emailvalidation(FormValues("emai_emailaddressbusiness"),"emai_emailaddressbusiness");
    emailvalidation(FormValues("emai_emailaddresssales"),"emai_emailaddresssales");
    emailvalidation(FormValues("emai_emailaddresssupport"),"emai_emailaddresssupport");

    }

    function PostInsertRecord()

    {

      // Handle post insert record actions here

    }


    function UpdateRecord()

    {

      // Handle update record actions here

    }


    function DeleteRecord()

    {

      // Handle delete record actions here

    }

    And another TLS with some changes to also make the phone number mandatory when creating a company

    PHONE


    function phonevalidation(x, y) {
        if (x.length > 0) {
            if (x.length < 4 || x.length > 20) {
                Valid = false;
                ErrorStr = CRM.GetTrans("GenCaptions", "Geschäftliche Telefonnummer Eingabe überprüfen (mind. 4 Ziffern)");
            }
        } else if (y == "phon_numberbusiness") {
            Valid = false;
            ErrorStr = "Geschäftliche Telefonnummer nicht angegeben";
        }
    }

    function InsertRecord() {
        // Handle insert record actions here
        phonevalidation(FormValues("phon_numberbusiness"), "phon_numberbusiness");
    }

    function PostInsertRecord() {
        // Handle post insert record actions here
    }

    function UpdateRecord() {
        // Handle update record actions here
    }

    function DeleteRecord() {
        // Handle delete record actions here
    }

Reply
  • 0 in reply to Sulfath Shajahan
    SUGGESTED

    Hi

    The link is unavailable so here is a Table Level Script that is working in Sage 2024 r2.

    Found on a Greytrix post (https://www.greytrix.com/blogs/sagecrm/2021/02/25/mandate-companys-phone-and-email-address-using-table-level-script/)

    Go to Administration -> Customizing -> Compan -> Table Level Script -> Create new

    1. Type in a name

    2. Choose script type Entity level with rollback and copy in the following script for E-Mail and Phone

    EMAIL

    function emailvalidation (x,y)
    {
    if (x.length>0)
    {
    apos=x.indexOf("@");
    dotpos=x.lastIndexOf(".");
    lastpos=x.length-1;
    if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos <2)
    {
    Valid = false;
    ErrorStr = CRM.GetTrans("colnames",y)+ " ["+x+"] " + CRM.GetTrans("GenCaptions","BadMailAddress");
    }
    }
    else if(y=="emai_emailaddressbusiness")
    {
    Valid = false;
    ErrorStr = "Geschäftliche E-Mail Adresse nicht angegeben";}
    }
    function InsertRecord ()

    {

    // Handle insert record actions here
    emailvalidation(FormValues("emai_emailaddressbusiness"),"emai_emailaddressbusiness");
    emailvalidation(FormValues("emai_emailaddresssales"),"emai_emailaddresssales");
    emailvalidation(FormValues("emai_emailaddresssupport"),"emai_emailaddresssupport");

    }

    function PostInsertRecord()

    {

      // Handle post insert record actions here

    }


    function UpdateRecord()

    {

      // Handle update record actions here

    }


    function DeleteRecord()

    {

      // Handle delete record actions here

    }

    And another TLS with some changes to also make the phone number mandatory when creating a company

    PHONE


    function phonevalidation(x, y) {
        if (x.length > 0) {
            if (x.length < 4 || x.length > 20) {
                Valid = false;
                ErrorStr = CRM.GetTrans("GenCaptions", "Geschäftliche Telefonnummer Eingabe überprüfen (mind. 4 Ziffern)");
            }
        } else if (y == "phon_numberbusiness") {
            Valid = false;
            ErrorStr = "Geschäftliche Telefonnummer nicht angegeben";
        }
    }

    function InsertRecord() {
        // Handle insert record actions here
        phonevalidation(FormValues("phon_numberbusiness"), "phon_numberbusiness");
    }

    function PostInsertRecord() {
        // Handle post insert record actions here
    }

    function UpdateRecord() {
        // Handle update record actions here
    }

    function DeleteRecord() {
        // Handle delete record actions here
    }

Children
No Data