Check for existing record in a table

nicolemccray
Tera Expert

I have a custom table that inserts some user fields each time a request is submitted.  How can I do a check on the table to see if the Employee ID already exists, and if it does, display a message to the requester and do not allow submission?

1 ACCEPTED SOLUTION

I was able to get this working by using an OnChange script:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var employeeId = g_form.getValue('employee_id');

if (employeeId != ''){

var ga_applicant = new GlideAjax("CorporateTravel");
ga_applicant.addParam("sysparm_name","getRequestInfo");
ga_applicant.addParam("employeeId", employeeId );
ga_applicant.getXML(ajaxResponse);

}

function ajaxResponse(serverResponse) {
var applicant = serverResponse.responseXML.getElementsByTagName("applicant");

if (applicant.length > 0){
already_applied = true;

alert("This person already has an application request in the system. Only one application request for a person may be submitted.");

g_form.setValue('understand_accept1', '');
g_form.setValue('understand_accept2', '');
g_form.setValue('understand_accept3', '');

}
}

}

View solution in original post

17 REPLIES 17

Jaspal Singh
Mega Patron
Mega Patron

Hi Nicole,

 

A before insert business rule would suffice which would compare by use of GlideRecord & if record exists it will abort the action of insert & display error message.

Dhananjay Pawar
Kilo Sage

Hi,

What type of field Employee ID it is?

thanks,

Dhananjay.

amit164
Giga Contributor

check this 

(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('incident');
gr.addQuery('description', current.description);
gr.query();
if (gr.next()) {
gs.addErrorMessage('Duplicate Incident already exists');
current.setAbortAction(true);
}

})(current, previous);

i have used same functionality for description on incident using before insert business rule