Question on Request Approval Notification

Community Alums
Not applicable

Hi There,

 

I have one Requirement on Request Table, 

 

when Request is created at that it will go to Approval, in previous Requirements i had Approval on RITM, but i need to achieve this on REQ now.

 

In That Notification Body, i have to add Request Details, for that i have written one mail Script FOR RITM, but i'm not sure, how can i change for Request table,

 

Please find the below mail script i have written for RITM Approval,

 

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
 var gr = new GlideRecord("sc_req_item");
    gr.addQuery("sys_id", current.sysapproval);
    gr.query();
      while(gr.next()) {
         var varown = new GlideRecord('sc_item_option_mtom');
        varown.addQuery("request_item", current.sysapproval);
        varown.addQuery("sc_item_option.value != ''null'' ");
        varown.orderBy("sc_item_option.order");
        varown.query();
         template.print('<table cellspacing="5" cellpadding="5" width="100%" style="border-color:#000000; height:30px; border-collapse:collapse;">');
      template.print('<tr><th style="width: 35%; border:1px solid black;" align="left">Variable</th><th style="border:1px solid black;" align="left">Answer</th></tr>');
      while (varown.next()){
            var visible = varown.sc_item_option.item_option_new.visible_summary;
            var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new);
            question.setValue(varown.sc_item_option.value);
            if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true && question.getLabel() != "null" && question.getDisplayValue() != "undefined"){
              template.print('<tr><td style="border:1px solid black;">' +  question.getLabel() + '</td><td style="border:1px solid black;"><strong>' + question.getDisplayValue() + '</strong></td></tr>');
            }
        }
               template.print('</table>');
    }
   
    })(current, template, email, email_action, event);
 
But here i don't want to send these details for RITM Approval., i want to send for REQUEST Approval.
 
Somebody please help me on this.
Thanks,
 
 
 
1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Base on what you want to send in the email you can change the values in the print. But this way you can navigate the sc_request when approval is for the request

Can you please try the below:-

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
 var gr = new GlideRecord("sc_request");
    gr.addQuery("sys_id", current.sysapproval);
    gr.query();
      while(gr.next()) {
var gr1= new GlideRecord("sc_req_item");
    gr1.addQuery("request", gr.sys_id);
    gr1.query();
 if(gr1.next()) {
         var varown = new GlideRecord('sc_item_option_mtom');
        varown.addQuery("request_item", gr1.sys_id);
        varown.addQuery("sc_item_option.value != ''null'' ");
        varown.orderBy("sc_item_option.order");
        varown.query();
         template.print('<table cellspacing="5" cellpadding="5" width="100%" style="border-color:#000000; height:30px; border-collapse:collapse;">');
      template.print('<tr><th style="width: 35%; border:1px solid black;" align="left">Variable</th><th style="border:1px solid black;" align="left">Answer</th></tr>');
      while (varown.next()){
            var visible = varown.sc_item_option.item_option_new.visible_summary;
            var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new);
            question.setValue(varown.sc_item_option.value);
            if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true && question.getLabel() != "null" && question.getDisplayValue() != "undefined"){
              template.print('<tr><td style="border:1px solid black;">' +  question.getLabel() + '</td><td style="border:1px solid black;"><strong>' + question.getDisplayValue() + '</strong></td></tr>');
            }
        }
               template.print('</table>');
    }
   }
    })(current, template, email, email_action, event);

 

Please mark my answer as correct based on Impact.

View solution in original post

3 REPLIES 3

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Base on what you want to send in the email you can change the values in the print. But this way you can navigate the sc_request when approval is for the request

Can you please try the below:-

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
 var gr = new GlideRecord("sc_request");
    gr.addQuery("sys_id", current.sysapproval);
    gr.query();
      while(gr.next()) {
var gr1= new GlideRecord("sc_req_item");
    gr1.addQuery("request", gr.sys_id);
    gr1.query();
 if(gr1.next()) {
         var varown = new GlideRecord('sc_item_option_mtom');
        varown.addQuery("request_item", gr1.sys_id);
        varown.addQuery("sc_item_option.value != ''null'' ");
        varown.orderBy("sc_item_option.order");
        varown.query();
         template.print('<table cellspacing="5" cellpadding="5" width="100%" style="border-color:#000000; height:30px; border-collapse:collapse;">');
      template.print('<tr><th style="width: 35%; border:1px solid black;" align="left">Variable</th><th style="border:1px solid black;" align="left">Answer</th></tr>');
      while (varown.next()){
            var visible = varown.sc_item_option.item_option_new.visible_summary;
            var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new);
            question.setValue(varown.sc_item_option.value);
            if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true && question.getLabel() != "null" && question.getDisplayValue() != "undefined"){
              template.print('<tr><td style="border:1px solid black;">' +  question.getLabel() + '</td><td style="border:1px solid black;"><strong>' + question.getDisplayValue() + '</strong></td></tr>');
            }
        }
               template.print('</table>');
    }
   }
    })(current, template, email, email_action, event);

 

Please mark my answer as correct based on Impact.

Community Alums
Not applicable

@Saurav11 ,

 

Its working, thank you.

Hello,

 

If my answer helped you can you also mark it as correct.

 

Thanks.