Email script is not working in notifications

Hemasundar_B
Tera Contributor

We have two notification rules: one for the "Opened By" user and another for the "On Behalf Of" user. However, the email script "getKnowledgeArticles" is not working for the "On Behalf Of" user notification.

Note: "getKnowledgeArticles" is a copied version of the email script "cxs_EmailSearchResults".

Can anyone suggest a fix for this issue?
Opened by  Notification:

Hemasundar_B_0-1743515981190.png

On behalf of Notification

Hemasundar_B_2-1743516197166.png

 

 

 

3 REPLIES 3

Shree_G
Mega Sage

Hello @Hemasundar_B ,

 

Please check the "getKnowledgeArticles" script and make sure any reference to "current.<field_name>" is valid and is getting the correct reference. Or share share the script to know more.


If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.

Here is the script:
(
function() {
    var searchRequest = cxs_App.getActions("cxs_TableActions", current).getEmailSearchRequest(email_action);
    if (!searchRequest || searchRequest == null || !searchRequest.query.freetext || !searchRequest.meta.get("runAsUser")) {
       
        return;
    }


    var imp = new GlideImpersonate();
    var previousUserId = imp.impersonate(searchRequest.meta.get("runAsUser"));
    var searchResponse = SNC.SearchService.search(searchRequest);
    var searchResponseObj = new JSON().decode(searchResponse.toJSON());

    template.print(cxs_App.getActions("cxs_FormatResults", searchResponseObj).usingMacro({
        "result_header_macro": "knowledge_results_header_email",
        "result_macro": "knowledge_search_results"
    }));

    if (previousUserId)
        imp.impersonate(previousUserId);
})();

Hemasundar_B
Tera Contributor
(function() {
    var searchRequest = cxs_App.getActions("cxs_TableActions", current).getEmailSearchRequest(email_action);
    if (!searchRequest || searchRequest == null || !searchRequest.query.freetext || !searchRequest.meta.get("runAsUser")) {
       
        return;
    }


    var imp = new GlideImpersonate();
    var previousUserId = imp.impersonate(searchRequest.meta.get("runAsUser"));
    var searchResponse = SNC.SearchService.search(searchRequest);
    var searchResponseObj = new JSON().decode(searchResponse.toJSON());

    template.print(cxs_App.getActions("cxs_FormatResults", searchResponseObj).usingMacro({
        "result_header_macro": "knowledge_results_header_email",
        "result_macro": "knowledge_search_results"
    }));

    if (previousUserId)
        imp.impersonate(previousUserId);
})();