Avoid duplicates while importing, with a composite key

Avoid duplicates while importing, with a composite key



I am trying to import records into a Form, 
and need to avoid duplicate entries ; the key for each row is a composite key made from field A and B. 




if (  (FORMX [A = input.A  && B = input.B ].count()  >=  1   ))


{

    alert "Duplicate!  Please check your entries!";
    cancel submit;
}



But the same script  does not work for ON ADD validation .   Can someone shed some light into this?