function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kim AdilKim Adil 

Javascript button to validate that multi-picklist field is populated when lookup field is populated

I have a requirement to remove the validation rule and include the logic in the Javascript button. Here is the details

I have a field called 'account__c'   (lookup field to account)
I have 3 multi-picklist fields, called:
multi-picklist A: values are: A1-A2-A3-A4
multi-picklist B: values are: B1-B-B3-B4
multi-picklist C: values are: C1-C2-C3-C4

if account selected is A, then ONLY 'multi-picklist A' field can be populated, the other two should NOT be populated. Same applies if account name is B or C.

I was actually using validation rule, and now I am asked to use Javascript button. We already have one in place that checks certain fields are not blank; it displays an alert if one field is blank.
I am asked to use the same logic I have in the validation rule, and add it to the button. I explained what needs to happen in my question above. Here is the code sample I have now:
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}

var invoiceID = '{!invoice__c.Id}'; //Get the inovice id

var agree = confirm("Are you sure you want to submit for approval?");

if(agree) 
{

if  ({!ISNULL(invoice__c.Field1__c)} ||
     {!ISNULL(invoice__c.Field2__c)} ||
     {!ISNULL(invoice__c.Field3__c)} ||
     {!ISNULL(TEXT(invoice__c.Field4__c))}) 

  {
     alert('Check Required Fields are populated ' );
  }
else
  {
    var result = sforce.apex.execute("ApexClassName","MethodName",{ InvoiceID : invoiceID });
    document.location.reload(true);
  }
 }

I appreciate the help out there. Thank you
NagendraNagendra (Salesforce Developers) 
Hi Kim,

Please check with this.
CASE(
    Account__r.Name,

    "Dell",
        IF(
            OR(
                NOT(ISBLANK(MSP_B__c)),
                NOT(ISBLANK(MSP_C__c)),
                ISBLANK(MSP_A__c)
            ),
            1,
            0
        ),

    "Microsoft",
        IF(
            OR(
                NOT(ISBLANK(MSP_A__c)),
                NOT(ISBLANK(MSP_C__c)),
                ISBLANK(MSP_B__c)
            ),
            1,
            0
        ),

    "Salesforce",
        IF(
            OR(
                NOT(ISBLANK(MSP_A__c)),
                NOT(ISBLANK(MSP_B__c)),
                ISBLANK(MSP_C__c)
            ),
            1,
            0
        ),

    0
) == 1

Regards,
Nagendra.P