What version of MAS and is it 90 or 200? I assume your script is set for the Pre-Write event
Your script is fine but what you're trying to accomplish is not conducive to scripting. When you click the Primary Contact hyperlink (which is the same as clicking the Contacts button from the dropdown in to the top right), MAS itself saves off the customer record (or save off vendor record if you clicked Primary Vendor). But this save triggers your script that prevents the save of the record. Hope you like pickles.
In Item Maintenance, a similar problem exists when trying to use a script to enforce a primary vendor for the item. However through storage variables and multiple scripts we can deal with the issue.
But here you can only deal with it in a half arsed way. What the below buys you is the ability to key in something in the Primary Contact field THEN you can click the Primary Contact hyperlink or the Contacts button in top right to bring up Customer Contact Maint. IOW you can't just first click that blue Primary Contact link (you'll have the same prob). You have to key in the contact code first. Hope that made sense.
1) Create a column Pre-Validatate script on ContactCode that does:
retVal = oScript.SetStorageVar(""SV_NewContact"", ""Y"")
2) Your current Pre-Write script gets conditionalized to run like this:
WasNewContactSet = """"
retVal = oScript.GetStorageVar(""SV_NewContact"", ""WasNewContactSet"")
If WasNewContactSet <> ""Y"" and primarycontact = """" Then
' show msg the contact code is required
End If
3) Optionally have a Post-Read script to clear storage var for next new customer:
retVal = oScript.SetStorageVar(""SV_NewContact"", ""N"")