jasonwucinski
Jun 5th, 2011, 03:20 PM
hello everyone. i have a controller that adds records to a database. in my database table i have a field that is declared unique. i would like to write code that tries to enter a new record but if an error is thrown due to that field already existing, i would like to do an update instead. below is the code i have started working on. i can trap an error but i dont know how to distinguish one error from another. thanks
def students = new XmlSlurper().parseText(linkedinResponse)
inkedinID = "${students.id}"
linkedinFirstName = " ${students.'first-name'}"
linkedinLastName = " ${students.'last-name'}"
def b = new LinkedinProfile(firstName:linkedinFirstName, lastName:linkedinLastName, linkedinId:linkedinID)
if( !b.save(flush:true) ) {
b.errors.each {
//is there a way to get the specific error code here?
println it
}
}
thanks
jason
def students = new XmlSlurper().parseText(linkedinResponse)
inkedinID = "${students.id}"
linkedinFirstName = " ${students.'first-name'}"
linkedinLastName = " ${students.'last-name'}"
def b = new LinkedinProfile(firstName:linkedinFirstName, lastName:linkedinLastName, linkedinId:linkedinID)
if( !b.save(flush:true) ) {
b.errors.each {
//is there a way to get the specific error code here?
println it
}
}
thanks
jason