4 Replies Latest reply on Nov 28, 2013 7:45 AM by mcollinge

    Accessing the User profile fields in the "Registration Validation" email template

       

      Hi,

       

       

      I'm currently modifying the "Registration Validation" email template using the admin console (ClearspaceX 1.4).

       

       

      I would like to be able to access the profile fields part of the user object but can't figure out the correct syntax to use in the freemarker template. Since  fields like name and username are accessible to the template I should be able to access the profile fields (Location, etc...) as well.  

       

       

      Any help is appreciated?

       

       

      cheers,

       

       

      James B.

       

       

        • Re: Accessing the User profile fields in the "Registration Validation" email template

          hi James,

           

          Great question, it took me a little bit to put it all together, but here's a sample that I think would output all the profile fields assuming you have a variable 'user':

          <# assign fields=jiveContext.profileFieldManager.profileFields />
          <# assign profile=jiveContext.profileManager.getProfile(user) />
          <#list fields as field>
              <#if field.visible>
                  <#if profile.get(field.ID?long)?exists>
                      <#assign p=profile.get(field.ID?long)>
                      <#if (p.value?exists || p.values?exists)>
                          <li>
                              <strong>${field.name?html}:</strong>
                              <span>
                                  <#if p.value?exists>
                                      <#if field.typeID == statics[http://"com.jivesoftware.community.ProfileField$Type"|http://"com.jivesoftware.community.ProfileField$Type"].URL.ID>
                                          <a href="${p.value?url}">${p.value?html}</a>
                                      <#else>
                                          ${p.value?html}
                                      </#if>
          
                                  <#elseif p.values?exists>
                                      <#list p.values as value>
                                          ${value?html}<#if value_has_next>,</#if>
                                      </#list>
                                  <#else>
                                      N/A
                                  </#if>
                              </span>
                          </li>
                      </#if>
                  </#if>
              </#if>
          </#list>
          

          Let us know if that helps,

           

          Cheers,

           

          AJ

            • Re: Accessing the User profile fields in the "Registration Validation" email template

              Hi Aaron,

               

              Thanks for the info. I tried it out but got a number of parsing errors with it. So after a bit of trial and error and reviewing the global/people.ftl template I managed to get it working. The final version I used looks like this;

               

              <#assign fields = statics[http://'com.jivesoftware.community.ProfileManagerFactory'|http://'com.jivesoftware.community.ProfileManagerFactory'].getProfileFieldManager().getProfileFields()/>
              <#assign profile = statics[http://'com.jivesoftware.community.ProfileManagerFactory'|http://'com.jivesoftware.community.ProfileManagerFactory'].getProfileManager().getProfile(user)/>
              
              <#list fields as field>
                  <#if field.visible>
                      <#if profile.get(field.ID?long)?exists>
                          <#assign p=profile.get(field.ID?long)>
                          <#if (p.value?exists || p.values?exists)>
                              <li>
                                  <strong>${field.name?html}:</strong>
                                  <span>
                                      <#if p.value?exists>
                                          <#if field.typeID == statics[http://'com.jivesoftware.community.ProfileField$Type'|http://'com.jivesoftware.community.ProfileField$Type'].URL.ID>
                                              <a href="${p.value?url}">${p.value?html}</a>
                                          <#else>
                                              ${p.value?html}
                                          </#if>
               
                                      <#elseif p.values?exists>
                                          <#list p.values as value>
                                              ${value?html}<#if value_has_next>,</#if>
                                          </#list>
                                      <#else>
                                          N/A
                                      </#if>
                                  </span>
                              </li>
                          </#if>
                      </#if>
                  </#if>
              </#list>
              

               

              cheers,

               

              James B.

            • Re: Accessing the User profile fields in the "Registration Validation" email template
              mcollinge

              Just adding an extra code snippet which I've just used in Jive 6.0.3.. this one gets a specific profile field (doesn't need to loop over the entire set) so it performs quite well. I'm hoping there aren't any errors in this.. I've just adapted it from a Macro we use so that it's a bit more generic.

               

              <#-- You can do this to get the profile field ID from sys props, instead of hard coding it -->
              <#assign myProfileFieldID = JiveGlobals.getJiveLongProperty('new.sys.prop.for.ID', 5010?long) />
              
              <#-- Function to get the profile field value.. pass in the user object, and ID of the field you're after -->
              <#function e14GetProfileField user profileFieldID>
                  <#if user?exists>
                      <#assign profile=jiveContext.profileManager.getProfile(user)>
                      <#if profile.get(profileFieldID)?exists>
                          <#assign p=profile.get(profileFieldID)>
                              <#if p.value?exists>
                                  <#return p.value />
                          </#if>
                      </#if>   
                  </#if>   
              </#function>