views:

40

answers:

1

Hi Guys,

I am trying to send an email to the customer whenever there is a new invoice generated. but to do that i need to get the id of invoice and customer. My problem is that the code which I am using to get the ids for invoice or customer is giving me inconsistent response, i mean it works sometimes and sometimes it does'nt

here is the relevant code :

protected Map getObjectsMap(Map domainMap){
    Map objectsMap = [:]
    domainMap.each{key,value->
        def dc = grailsApplication.domainClasses.find{it.getFullName().equals(key)}
        def obj = dc.clazz.get(value)
        if(!obj)
            log.error "Could not find object of type $key with id=$value"
        String objectName = key.substring(key.lastIndexOf(".")+1)
        objectName = objectName.charAt(0).toLowerCase().toString() + objectName.substring(1)
        objectsMap.put(objectName, obj)
    }
    return objectsMap
}

in the domainMap which I am passing as parameter I am passing the complete name of class and id of object as Map. and using the code above I want to get the object of that class with that ID so that I can get its other attributes to work with and i am returning a map of objects with their class names as key.Any reason on why it is not behaving consistently.

A: 

Im confused, are you doing this in a script or from within your application? why not

def invoices = MyInvoiceDomainClass.findAll()
invoices.each{invoice->
   invoice.whatever...
}
hvgotcodes