On Load script causing application error

On Load script causing application error

I have the follow code that simply looks up a CRM Contact record and does some basic conditional logic. It works okay if a record is returned from CRM, however if nothing is returned for the criteria it shows an application error when it gets to this line:

crmContactMap = crmContact.get(0);

I thought it is because it's trying to work with a null record, so I've put this line within conditional logic that only runs if the record returned is not null. Full code is below.

I can't figure out what I'm doing wrong. Any help would be appreciated.


crmContactSearchString = "(Login Email|=|" + input.Email + ")";
crmContact = zoho.crm.searchrecords("Contacts",crmContactSearchString);
crmLoaded = ifnull(crmContact,0);
if(crmLoaded != 0)
{
crmContactMap = crmContact.get(0);
login_status = crmContactMap.get("Login Status");
login_email = crmContactMap.get("Login Email");
if(login_email == null)
{
alert "Login account does not exist";
}
else if(login_status != "Active")
{
alert "Login account is not active";
}
}
else
{
alert "No such login account";
}