Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

setAttribute through IF-Statement

Avatar

Former Community Member

Hello

I'm trying to make a form, that picks the recipient depending which value a textfield has (dropdown value -> textfield)

Sounds really simple, hm?

But I'm having huge problems. The programm doesn't seem to like me at all .

//END OF DROPDOWN

<event activity="change">
   <script contentType="application/x-javascript">

   if (
    xfa.event.newText == "Service1" ||
              xfa.event.newText == "Service 2" ||
             xfa.event.newText == "Service 3" ||
              xfa.event.newText == "Service 4" ||

   {
  responsible.rawValue = "Person1"
   }
   else
   {
   responsible.rawValue = "Person2"
   }

   </script>
   </event>

---

<field h="15.0001mm" name="Supervisior" w="97.3mm" x="0.0024mm" y="215.5mm"> 

<event activity="exit">

<script contentType="application/x-javascript">

   if (responsible.rawValue == "Person1")
    {

      document.getElementById('sendmail')[0].setAttribute("target", "mailto:address1@provider.com");

     }
    else
    {
    document.getElementById('sendmail')[0].setAttribute ("target", "mailto:address2@studer.com");
    }
</script>
</event>
</field>

   

<field h="5.9993mm" name="mail2" presence="hidden" w="28.575mm" y="-0.0001mm">

<event activity="click">


<submit format="pdf" id="sendmail" textEncoding="UTF-8"/> // IN HERE I WANT THE TARGET ADDRESS


</event>
</field>


 

Can someone help me with this problem?

Sorry about the code structure, but the syntax highlighting is a bit confusing in this forums.

I hope you can read it

Thanks in advance

Sincerly

Oddy

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Problem solved. I used the preSubmit event and resolveNode class.

Here's my code, if anyone cares:

<field h="5.891mm" name="mail2" presence="hidden" w="28.5732mm" x="0.1771mm" y="0.1314mm">

     <?templateDesigner isEmailSubmitObject true?>

     <ui>

      <button/>

      </ui>

      <event activity="click">

           <submit format="pdf" textEncoding="UTF-8"/>

      </event>

      <event activity="preSubmit" ref="$form">

       <script contentType="application/x-javascript">

           var vSubmit2 = this.resolveNode("#event.#submit"); // <-- spricht submit-element im event click an

          var antragsteller = Vorname.rawValue + " " + Mitarbeitername.rawValue;

          vSubmit2.format = "pdf";

          var vSubject2 = "Absenz genehmigt";

          mail2.resolveNode("#event.#submit").target = "mailto:" + vEmpfaenger2 + "?subject=" + vSubject2 + "&amp;body=" + "Hallo, bitte diese Absenz noch nachtragen. Danke.";</script>

     </event>

</field>

View solution in original post

1 Reply

Avatar

Correct answer by
Former Community Member

Problem solved. I used the preSubmit event and resolveNode class.

Here's my code, if anyone cares:

<field h="5.891mm" name="mail2" presence="hidden" w="28.5732mm" x="0.1771mm" y="0.1314mm">

     <?templateDesigner isEmailSubmitObject true?>

     <ui>

      <button/>

      </ui>

      <event activity="click">

           <submit format="pdf" textEncoding="UTF-8"/>

      </event>

      <event activity="preSubmit" ref="$form">

       <script contentType="application/x-javascript">

           var vSubmit2 = this.resolveNode("#event.#submit"); // <-- spricht submit-element im event click an

          var antragsteller = Vorname.rawValue + " " + Mitarbeitername.rawValue;

          vSubmit2.format = "pdf";

          var vSubject2 = "Absenz genehmigt";

          mail2.resolveNode("#event.#submit").target = "mailto:" + vEmpfaenger2 + "?subject=" + vSubject2 + "&amp;body=" + "Hallo, bitte diese Absenz noch nachtragen. Danke.";</script>

     </event>

</field>

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----