Skip to main content
Question

Emails triggered by Approval of Decision


Forum|alt.badge.img+4
  • Sidekick (Customer)
  • 24 replies

When a decision task is taken and Denied this is successfully triggering an email to the affected user based on the Denied sub process and associated Task.  Approved decisions are not triggering an email, Approvals don’t generate a sub process they just simple move the process onto the next task. Each task is different depending on the process so I cannot effectively hang an approval email from those. Is there some way to trigger an email based on the ‘Answer’ to a decision?

5 replies

Forum|alt.badge.img+8
  • Hero (Customer)
  • 44 replies
  • April 28, 2023

Hi, 

Yes you can trigger an email to fire on the action processor, we do this by using checkAnswer:

 


        [[ Send Mail to affected user Decision Approval Received ]], 
        [[ EVENT_TYPE == "d"
            and ACT_TYPE_SC == "CLOSURE" 
            and (CATEGORY_SC == "DECISION" or
            CATEGORY_SC == "AUTHORIZATION" or 
            CATEGORY_SC == "APPROVALS")
            and checkAnswer("Yes", EVENT_ID) ]], 
         strSendMailV2 .. "TEMPLATE=SM_INTERNAL_APPROVAL_RECEIVED RECIPIENTS=TO_AFFECTED",  
        "continue"  
    },

Hope this helps you. 

 

Kev


Forum|alt.badge.img+4
  • Author
  • Sidekick (Customer)
  • 24 replies
  • April 28, 2023

Thanks @KevinM I’ll have a play around with this


Forum|alt.badge.img+8
  • Hero (Customer)
  • 44 replies
  • April 28, 2023

Additionally should have added that Check Answer is a function, this is added at the bottom of our action_processor_rules_conf.lua

 

function checkAnswer(parmAnswer, parmEventId)

    local sSql = [[SELECT
         answer 'ANSWER'
        FROM rproc_task
        INNER JOIN rproc_dtl
        ON rproc_task.rproc_dtl_id = rproc_dtl.rproc_dtl_id
        INNER JOIN rproc_decisions 
        ON (rproc_decisions.rproc_task_id = rproc_task.rproc_task_id
            and rproc_decisions.rproc_decision_id = rproc_task.answer_id)
        WHERE
        rproc_task.incident_id = ]] .. parmEventId
        
    local result,err = DB:sql(sSql)
    if err then 
        LOGGER:error("Error in SQL when checking for Decision Answer. Error: " .. (err or "??") .. "\nSQL: " .. stringify(sSql))
        return
    end
    
    if result['ANSWER']:upper() == parmAnswer:upper() then
        return true
    else
        return false
    end
end

ANSWER_VALUE = ""
function getDecisionAnswer(eventId, actRegId,ans, rmks)
    local actRegId = actRegId or 0
    local ans = ans or ""
    local ok,err = DB:sql([[
            SELECT answer 'ANSWER_VALUE'
            FROM act_reg
            INNER JOIN rproc_task ON rproc_task.incident_id = act_reg.incident_id
            INNER JOIN rproc_dtl ON rproc_dtl.rproc_dtl_id = rproc_task.rproc_dtl_id
            INNER JOIN rproc_decisions ON rproc_task.rproc_task_id = rproc_decisions.rproc_task_id
            WHERE answer = ']] .. ans .. [['
            AND act_reg.act_reg_id = ]] .. actRegId
            )
    if err then 
        LOGGER:error("Error in SQL when checking for Decision Answer. Error: " .. (err or "??"))
        return
    end
    if ok and ok["ANSWER_VALUE"] and (ok["ANSWER_VALUE"] or "") ~= "" then
        local ANSWER_VAR = ok["ANSWER_VALUE"]
        LOGGER:info("Ready to run external command for " .. actRegId .. ": " .. strETMNoUser .. "'ECC Make Decision' EventID='" .. eventId .. "' Answer='" .. ANSWER_VAR .. "' Remarks='" .. rmks .. "';")
        os.execute(strETM .. "'ECC Make Decision' EventID='" .. eventId .. "' Answer='" .. ANSWER_VAR .. "' Remarks='" .. rmks .. "';")
        -- return ok["ANSWER_VALUE"]
        return
    else
        return
    end
end


Forum|alt.badge.img+4
  • Author
  • Sidekick (Customer)
  • 24 replies
  • June 15, 2023

@KevinM We’ve been trying this but the action processor is really unhappy with some part of it. I’ll keep trying


Forum|alt.badge.img+5
  • Do Gooder (Employee)
  • 17 replies
  • June 22, 2023

Since you will only have a single stage created after the Approval, you can use an AP rule to trigger SmartMail based on that stage action on the parent event. The sample rule below could be extended if needed to only send on certain workflows or offerings.

    {
        [[ Send Mail to affected user Decision Approval Received ]], 
        [[ (EVENT_TYPE == "r" or EVENT_TYPE == "s")
            and ACT_TYPE_SC == "POST APPROVAL STAGE SC" 
        ]], 
         strSendMailV2 .. "TEMPLATE=SM_INTERNAL_APPROVAL_RECEIVED RECIPIENTS=TO_AFFECTED",  
        "continue"  
    },


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings