Skip to content
Snippets Groups Projects
onValueChange.js 1.12 KiB
Newer Older
S.Listl's avatar
S.Listl committed
import("system.vars");
import("system.neon");
import("system.util");
import("system.mail");
import("DocumentTemplate_lib");
import("Entity_lib");

if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
{
Johannes Hörmann's avatar
Johannes Hörmann committed
    // note: could not use only the valueProcess from $field.content because then it refreshed $field.content just before save.
    // --> only set in $field.content.valueProcess if $field.content is null and set it from here only if MASK triggered change
    [content, type] = DocumentTemplateUtils.getTemplateContent(vars.get("$local.value"), new FileUpload(vars.get("$field.bindata")));
    vars.set("$context.currentTemplateType", type);
    vars.set("$field.content", content)
    
    // TODO: load subject without loadTemplate again... maybe return with getTemplateContent() above?
    var templateId = vars.get("local.value");
Johannes Hörmann's avatar
Johannes Hörmann committed
    var template = DocumentTemplate.loadTemplate(templateId, undefined, false);
S.Listl's avatar
S.Listl committed
    if (template.type == DocumentTemplate.types.EML)
    {
        let subject = mail.parseRFC(util.decodeBase64String(template.content))[mail.MAIL_SUBJECT];
        neon.setFieldValue("$field.SUBJECT", subject);
    }
}