I need to make an Ajax query to call a method in a Service object that takes 3 parameters and returns a boolean. I then use this Boolean for a validation message that happens pre-post.
This is what I have at the moment (not working) but I’ve tried other things but to no avail. We’re using JQuery and Grails:
var isUnique = ${remoteFunction(
service: 'Project',
action:'checkUniqueUserProjectId',
params:{
// These values are from hidden fields in the form.
// userId and projectId are string values and the group is an object
uniqueId: userId,
group: userGroup,
projectId: myProjectId
}
)}
Here’s the method that is called in the ProjectService:
// Check whether or not a Project with the provided uniqueId already exists
// in the database that is not itself.
def checkUniqueUserProjectId(uniqueId,group,projectId) {
def filterCriteria = Project.createCriteria()
def projectList = filterCriteria.list {
and {
eq("userProjectId", uniqueId)
eq("group", group)
ne("id",projectId)
}
}
if(projectList.empty)
return true
else
return false
}
Any help would be greatly appreciated!
I ended up using a remote function with the code as follows:
….
ProjectController
Thank you everyone for your help! You helped lead me in the right direction 🙂