How to determine if a CUSTOMER field value is an Account or a Contact through JavaScript

 

How to determine if a CUSTOMER field value is an Account or a Contact through JavaScript



   CasePopulatePrimaryContact: function (executionContext) 

   {

        var formContext = executionContext.getFormContext();

        debugger;

        var customer = formContext.getAttribute("customerid");

        if(customer == null || customer == undefined)

        {

            return;

        }

        //Lookup is an array. Need to get first object.

        var customerType = customer.getValue()[0].entityType;

        if (customerType == "account")

        {         ........

        }

        else if (customerType = "contact")

        {           ..........

        }

        else

        {            ......

        }       

    }


//If you need customerid or customer name, below script could be your reference.

     var CustomerId = customer.getValue()[0].id;

alert(CustomerId);

    var CustomerName = customer.getValue()[0].name;
    alert(CustomerName);

No comments:

Post a Comment