6 Replies Latest reply on Jan 14, 2019 10:48 AM by Sarah N'maan

    How can I retrieve a field value from the form and put it in HTML field ?

    Sarah N'maan Apprentice

      Dear All.

       

      How can I retrieve a field value from the form and put it in HTML field ? for example this text: (This Agreement will be effective from: July 8th, 2015, and will remain valid for a period of 12 months and will be renewed automatically if there are no additional requirements from one of the stakeholders.)

      I need to add this text to HTML field but I need the date to be read from start date field. How can I achieve this?

       

      By using email templates, field's values can be returned like $(ChangeNumber) but when using the same context $(StartDate) in HTML field to retrieve the value of it, it retrieves the text the same as I typed it not the value of it. like this:

      (This Agreement will be effective from: $(StartDate), and will remain valid for a period of 12 months and will be renewed automatically if there are no additional requirements from one of the stakeholders.)

       

      The HTML code for the above:

      <div style=""><span style="font-family: Calibri, sans-serif;"><span style="background-color: rgb(255, 255, 255);">This Agreement will be </span><b style="background-color: rgb(255, 255, 255);">effective</b><span style="background-color: rgb(255, 255, 255);"> from: $(StartDate)</span><span style="background-color: rgb(255, 255, 255);">, and will remain

      valid for a period of 12 months and will be renewed automatically if there are

      no additional requirements from one of the stakeholders.</span><b style="background-color: rgb(255, 255, 255);"><o:p></o:p></b></span></div>

       

       

      <div style="background-color: rgb(255, 255, 255);"><br></div>

       

       

      Many thanks.

        • 1. Re: How can I retrieve a field value from the form and put it in HTML field ?
          vee Specialist

          I have this issue as well when the whole block of HTML is wrapped in a $(...) (I have a lot of If statements in my emails)

          I copied and pasted the snipped you provided and it worked fine, so that makes me think the snipped is contained inside a larger piece of HTML, some of which is wrapped with $(...)? If so, you have to use open and close quotes, and "+" signs.

           

          Example:

          If you have $(<div style="") and you want to pull field values in, you need to do something like this:

           

          $('<div style="" ' + field + '</div>')

           

          Notice the use of single quotes ' ' and double quotes " " also the lack of $( ) around "field". You can't nest $( ) inside another $( )

           

          So for your code snippet you can try to do this:

           

          $('<div style=""><span style="font-family: Calibri, sans-serif;"><span style="background-color: rgb(255, 255, 255);">This Agreement will be </span><b style="background-color: rgb(255, 255, 255);">effective</b><span style="background-color: rgb(255, 255, 255);"> from: '  + StartDate + '</span><span style="background-color: rgb(255, 255, 255);">, and will remain

          valid for a period of 12 months and will be renewed automatically if there are

          no additional requirements from one of the stakeholders.</span><b style="background-color: rgb(255, 255, 255);"><o:p></o:p></b></span></div>

          <div style="background-color: rgb(255, 255, 255);"><br></div>')

          • 2. Re: How can I retrieve a field value from the form and put it in HTML field ?
            Sarah N'maan Apprentice

            @ vee

             

            thank you for your response. I am able to retrieve a field value in the way you mentioned.

            But I have a case, I want to read all the services linked to the record. Is there a way that I can use to list all services names that are linked to the record as child object ?  I am also want to list them inside the HTML field

            • 3. Re: How can I retrieve a field value from the form and put it in HTML field ?
              vee Specialist

              Yes, you can use ForEachChild to achieve this. You can also include some HTML into the function to make things a bit nicer if you need to.

               

              Here's an example of what I did for related knowledge links to Incident. We wanted a link to all related knowledge articles linked to a Incident record to send in the resolution email to the client:

               

              $(ForEachChild("Incident#",   RecId,   "FRS_Knowledge#UniKnowledge.",   "if Collection == 'All staff' then [Incident#]GeneratedLinksToKnowledge + '<a href=' + URL_Permalink_SelfService + '>' + Title + '</a><br>' else [Incident#]GeneratedLinksToKnowledge",   "Title"))

               

              We have a knowledge object called "UniKnowledge", the above grabs the title of the article and hyperlinks it and sends the value to a field titled "GeneratedLinksToKnowledge". I used to do this directly in the resolution email but it got a bit messy and ISM threw weird errors when the mix of HTML and functions got too long, so now I just have a trigger that builds the link in a hidden field, then drops that field into the email. But you likely won't have that problem if you're doing all this to a HTML field with triggers and such.

               

              Hope this helps, let me know if you need more assistance.

              1 of 1 people found this helpful
              • 4. Re: How can I retrieve a field value from the form and put it in HTML field ?
                Sarah N'maan Apprentice

                Many thanks @ vee

                 

                I used the below calculation rule and It worked perfectly, I was able to retrieve the services name as I exactly desire. I saved the values inside a text field called ServiceList. In ServiceList field, I'm getting each service name in separate row but in the HTML field the list of services names appeared in one row like this: ServiceName1, ServiceName2,

                Do you have an idea on how can I list each service name in separate row like this inside the HTML field: ?

                ServiceName1

                ServiceName2

                ServiceName3

                 

                Calculation Rule on ServiceList= $(ForEachChild("ServiceAgreement#SLA",  RecId,  "CI#Service.SLAAssocCIService", "if Status='Production' then  Name + ',\n'else ''",  "Name ASC"))

                • 5. Re: How can I retrieve a field value from the form and put it in HTML field ?
                  MattH Apprentice

                  Your expression is separating each Name with ',\n', which is a comma and a line break. When HTML is rendered it will usually replace line-break characters with other white-space characters such as a regular space, so each comma+line-break is being rendered as comma+space. Try replacing the '\n' with an HTML line break, '<br>'.

                   

                  You might also consider having the rule generate a list, using <ul> and <li> tags. This will typically render as a bulleted list.

                  Calculation Rule on ServiceList= $('<ul>' + ForEachChild("ServiceAgreement#SLA",  RecId,  "CI#Service.SLAAssocCIService", "if Status='Production' then  '<li>' + Name + '</li>' else ''",  "Name ASC") + '</ul>')

                  1 of 1 people found this helpful
                  • 6. Re: How can I retrieve a field value from the form and put it in HTML field ?
                    Sarah N'maan Apprentice

                    Thank you @ MattH . I changed ServiceList field type to HTML and It works