Use inbound email action to update work_notes

Wade Clairmont
Tera Guru

Hey all,

I have an inbound email action that I need to update work_notes in an extended task table.   However, it seems I am missing something.   The action runs every time, but no update to work_notes field.   Any ideas?   Thanks in advance.

Here is my script:

gs.include('validators');

if (current.getTableName() == "sysapproval_approver") {

      var curRec = current.document_id; //associated TASK Number to find related RFE

        if (gs.hasRole("u_request_for_expenditure_user")) {

              if (email.subject.indexOf("Comments for Finance") >= 0) {

                  var worknote = "reply from: " + email.origemail + "\n\n" + email.body_text;     }

                  var g = new GlideRecord('u_request_for_expenditure'); // find related RFE for update

                  g.addQuery('sys_id', curRec);

                  g.query();

                  while(g.next()) {

                      g.work_notes = worknote;

                      g.update();   }

      }

}

1 ACCEPTED SOLUTION

gs.include('validators');


if (current.getTableName() == "sysapproval_approver") {


      var curRec = current.document_id; //associated TASK Number to find related RFE



        if (gs.hasRole("u_request_for_expenditure_user")) {


              if (email.subject.indexOf("Comments for Finance") >= 0) {


                  var worknote = "reply from: " + email.origemail + "\n\n" + email.body_text;     }


                  var g = new GlideRecord('u_request_for_expenditure'); // find related RFE for update


                  g.addQuery('sys_id', curRec);


                  g.query();


                  while(g.next()) {


                      g.work_notes = worknote;


                      g.update();   }


      }


}



Your variable is declared in that if statement block. Try the code listed below and see if it works.



gs.include('validators');


if (current.getTableName() == "sysapproval_approver") {


      var curRec = current.document_id; //associated TASK Number to find related RFE


      var worknote = '';   //Added this line



        if (gs.hasRole("u_request_for_expenditure_user")) {


              if (email.subject.indexOf("Comments for Finance") >= 0) {


                  var worknote += "reply from: " + email.origemail + "\n\n" + email.body_text;     }


                  var g = new GlideRecord('u_request_for_expenditure'); // find related RFE for update


                  g.addQuery('sys_id', curRec);


                  g.query();


                  while(g.next()) {


                      g.work_notes = worknote;


                      g.update();   }


      }


}



Let me know if it works! Thanks


View solution in original post

6 REPLIES 6

that's because the scope of worknotes variable was limited to if block.


must appreciate the keen eyes of Harman...Like it!


It should just work. Just to fiddle around, have you tried -



replacing body_text with body_html


set comments/worknotes using field action instead of script