How to check Address Type unicity

Hi !

I'd like to implement on SageCRM 7.3 the following controls and I'm looking for ideas because it refers to a very specific point in the system Address Types :

  1. First control : Making Address Type required (Link_addressType). As it is not a field available in screen customisation, I don't see how to do that (even if it's possible ?). One can not save an address without having checked at least one checkbox type
  2. Second control : wether or not there is already one Address of Billing Type for the company (current context). If there is already one address for that particular "Billing" type, don't allow to save and give a user message : "There already is a "Billing" address. You must update it or disable it and recreate a new one before saving this new one" (or something like that)

Thanks for your advice

  • 0

    You should be able to handle this with a combination of a company Entity Level script with rollback to handle the entry of a new Company and Address

    and to handle updates of existing addresses and additional addresses on an existing company you can use a Validation rule. The value of the field will be in the FormValues()

    Validating the address using a Entity Level script will be a bit like the validation of emails and phone numbers. See: community.sagecrm.com/.../validating-phone-numbers-and-email-addresses.aspx

  • 0

    Ok,

    juste try but it doesn't work wether I add a tablescript on company or on address.

    Tried several things and even that basic one doesn't do anything :

    function InsertRecord()

    {

    // Handle insert record actions here

    Valid = false ;

    ErrorStr = "Test";

    //AddressTypeValidation(FormValues("AdLi_TypeBilling");)

    }

    function PostInsertRecord()

    {

    // Handle post insert record actions here

    }

    function UpdateRecord()

    {

    // Handle update record actions here

    Valid = false ;

    ErrorStr = "Test";

    //AddressTypeValidation(FormValues("Link_AddressType");)

    }

    function DeleteRecord()

    {

    // Handle delete record actions here

    }

    Script Type is "Entity Level with Rollback"

    the other fields are empty or let with devaulft value.

    Loggin level is high

    nothing happens, no log.

    version is Sage 100 CRM i7 8.01 build 7.3.b (latest French release)

    SQL Server 2012, OS win 7 x64 (on a VMware)

    any idea?

  • 0

    You can check if an address has a type checked when saving by using:

    Values("AdLi_TypeBusiness");

    Values("AdLi_TypeBilling");

    Values("AdLi_TypeShipping");

    If they are checked, they give a value of 'on', so this would work in the validate script of any field on that screen:

    var Bus = Values("AdLi_TypeBusiness");

    var BillMurray = Values("AdLi_TypeBilling");

    var Ship = Values("AdLi_TypeShipping");

    if(Bus!='on'&&BillMurray!='on'&&Ship!='on')

    {

    errorstr = 'Please choose at least one type for this address';

    valid=false;

    }

  • 0

    Thank you Toby it works !

    I didn't know that I could check other fields in the ValidateScript. The only small issue is that the Red cross is related to the field Addr_Address1 where I put the control but I can deal with it !

    Proconsult

  • 0

    You could also use AJAX and a .asp file to go off and check if an address of that type is associated to the company, and show an alert.

    First thing is create a simple view:

    SELECT AdLi_CompanyID,adli_type

    FROM Address_Link

    WHERE adli_deleted IS NULL AND AdLi_PersonID IS NULL AND adli_type IS NOT NULL


    For the sake of this example, it will be called vCompanyAddressType


    Then create a .asp file to query it, with the company ID you are currently in:


    <%

    CompId = Request.QueryString("Denzel")

    p = CRM.FindRecord("Company, vCompanyAddressType", "adli_type = 'Business' AND adli_companyId =" + CompId);

    Response.Write(p.adli_companyid);
    %>


    Then you need to create a function to go off an pass info to this page, so you can check its type. At the moment, I cannot think how to pass the type in, so you would have to make a page and function for each, that is why I have highlighted the above.

    Then create your function:


    function CheckAddress() {
    var strQS = window.location.href.split('?')[1]
    var strAddr;
    if (window.location.href.indexOf("eware.dll")==-1) {
    strAddr = window.location.href.split('CustomPages')[0];
    } else {
    strAddr = window.location.href.split('eware.dll')[0];
    }
    compid = crm.getArg("Key1",crm.url());
    var strURL = strAddr + 'CustomPages/CheckAddress.asp?Denzel= ' + compid + '&' + strQS;

    XmlHttp = new XMLHttpRequest();

    XmlHttp.open('GET',strURL,false);
    XmlHttp.setRequestHeader('Content-Type', 'text/xml');
    XmlHttp.send(null);
    var strHtml = XmlHttp.responseText;
    XmlHttp=null; // always clear the XmlHttp object when you are done to avoid memory leaks

    if(strHtml > 0)
    {
    alert("There is one of those.");
    }

    }


    Using jquery, you can then add the onchange attribute to the check box:


    $(document).ready(function() {
    $('[name="AdLi_TypeBusiness"]').attr("onchange","CheckAddress();");
    });
    t>



    This then means, when I check the 'business' address check box, the company ID I am in is passed to the .asp file, and a result written back, if it is greater than 0 then I get an alert telling me there is a business address already associated to it.

    It is not perfect as it sits, but it is another thing to look at along with Jeffs suggestion.