Moqui send#AuthcCodeEmail fails on quiWorker: No account found for username

Hi everyone,

I’m running into an issue with Moqui when trying to send an authentication code email. I want to send a code to each registered user’s email address for verification.

Logs:

isUsernameExist dana
factorId 100005
ERROR quiWorker-10   o.moqui.i.c.MessageFacadeImpl No account found for username dana
WARN quiWorker-10   o.moqui.i.s.ServiceCallSyncImpl Found error(s) before service org.moqui.impl.UserServices.send#AuthcCodeEmail, so not running service. Errors: No account found for username dana

Code snippet:

def isUsernameExist = ec.entity
        .find('moqui.security.UserAccount')
        .condition('username', username)
        .one()
        .username

println "isUsernameExist " + isUsernameExist

def factorId = ec.service.sync()
        .name('org.moqui.impl.UserServices.create#UserAuthcFactorEmail')
        .parameters([
                userId: userId,
                factorOption: emailAddress
        ])
        .call()
        .factorId
println "factorId " + factorId

ec.service.sync()
        .name('org.moqui.impl.UserServices.send#AuthcCodeEmail')
        .parameters([
                factorId: factorId
        ]).call()

From my debug prints, the username (dana) exists and the factorId is created successfully. But when the send#AuthcCodeEmail service runs (through quiWorker), it fails with “No account found for username dana.”

For context, I’m creating the user account with this service call, after creating I am trying to send an email.

<service-call name="mantle.party.PartyServices.create#Account" in-map="true" out-map="result"/>

One more thing I noticed: sometimes the email does get sent successfully, but most of the time it fails with the above error. That makes me wonder if this is a timing/context issue with the worker.

Any help would be greatly appreciated!