1
votes

As you can tell from all of my earlier questions I'm attempting to learn some NetSuite Suitescript to truly leverage NetSuite. With that being said I've got to where I can search for the max employee number and then act accordingly. Now what I want to do is to search for an email address to see if the one given is a duplicate. Essentially ensure the workflow will not create a new employee record if an employee record already exists with the email address.

I have the following so far...

function checkDuplicate(givenEmail){
    var filters = new nlobjSearchFilter('email', null, givenEmail);
    var colums = new nlobjSearchColumn('email');
    var results = new nlobjSearchRecord('employee', null, filters, columns);
    if(results[0].getValue('email') == null) return false;
    else return true;
}

Is there a better/easier way? I'll be testing this out.

1

1 Answers

1
votes

Your syntax is a bit off. Based on your script, I suggest apply the following modifications:

function checkDuplicate(givenEmail){
    var filters = new nlobjSearchFilter('email', null, 'is', givenEmail);
    var results = new nlapiSearchRecord('employee', null, filters);

    return (results != null);
}

Since you're just checking if there are any matching results, an nlobjColumn isn't needed. Also, if there aren't any matches, nlapiSearchRecord returns a null.

As an additional note, it seems you're still a bit rough on your SuiteScript (at least with the search APIs), so I suggest looking up "Searching with SuiteScript" in the NetSuite Help Center.