Name

sn_hr_core.VariableReplacer

Description

For now, this simply contains a small function used to replace variables in template fields that support variable replacement

Script

var VariableReplacer = Class.create();
VariableReplacer.prototype = {
  initialize: function() {
      this.variablesToIgnore = gs.getProperty('sn_hr_core.task_template_variable_ignore', '').split(',');
  },
  replaceFieldTokens: function(text, record) {
      if (!text)
          return text;

      var self = this;
      return text.replace(/\$\{([^}]+)\}/g, function(matchStr, field) {
          var parts = field.split('.');
          var shortVar = parts[parts.length - 1];
          var variableShouldNotBeReplaced = self.variablesToIgnore.indexOf(shortVar) > -1;
          if (variableShouldNotBeReplaced)
              return gs.getMessage('Unavailable');
          if (!record.getElement(field))
              return '';
          return record.getElement(field).getDisplayValue();
      });
  },

  type: 'VariableReplacer'
};

Sys ID

6b7cc1055302201041bbddeeff7b1294

Offical Documentation

Official Docs: