1

i want to add a Business Rule in ServiceNow. When i add a new record to the sys_email table with "To"(direct) or "CC"(copied) i want before insert into the table a rule who copy the "to" or "cc" filled fields into the "bcc" filed after the submit and delete the "to" and "cc" entrys. This is my code so far which does not change something. Iam rly new to ServiceNow maybe someone can help me?

 (function executeRule(current, previous /*null when async*/) {

var gr = new GlideRecord('sys_email');

//gr.newRecord();

gr.addQuery('direct','current.direct');
gr.addQuery('copied','current.copied');
gr.query();
while(gr.next()) 
{
 gr.blind_copied = current.direct +', '+ current.copied;
 gr.update();
}


  })(current, previous);
SirDaniel
  • 23
  • 5
  • ....this is one of those "but why?" questions. This will destroy email chains and multi-party conversations. It's going to be worked around almost immediately by adding a header "please add these people when you reply". What is the actual problem you're trying to solve? What issue is it you're worried about? – Clockwork-Muse Sep 09 '19 at 19:40

1 Answers1

1

To do this, make sure to use a before business rule on insert and update for the sys_email table. You are able to alter the fields in the current record before it is inserted.

(function executeRule(current, previous /*null when async*/) {

    // create variables for use from current record
    var to = current.direct;
    var cc = current.copied;
    var bcc += to + '; ' + cc;

    // update the current record
    current.direct = '';
    current.copied = '';
    current.blind_copied = bcc;

})(current, previous);
Kirk
  • 16,182
  • 20
  • 80
  • 112