5 Replies Latest reply on Sep 5, 2012 7:56 AM by sethkyle

    Embedding a jive user attruibute in an URL in an HTML widget

    milojive

      I want to pass the jive user name as a parameter in the url to my survey gizmo surveys (using the survey gizmo app)

       

      1. How can i display a jive user attribute (for the logged in user) on a HTML page?

       

      2. Can i then embed this in a url?

       

      3. Have you found another way of passing the current jive user to survey gizmo?

        • Re: Embedding a jive user attruibute in an URL in an HTML widget
          milojive

          The following code shows how to create a personalized link that contains the jive user id and the jive username

          This can be used in a url to a survey gizmo survey to pass information about the user and link the survey to the current jive user

          It uses jQuery to query data on the current page.

          To access jquery you normally use $ at the start of a query line in jive you have to use $j

          You have to be an administrator to paste script into an html widget

           

          Script works as follows

           

          1. Create some place holders in the page where we will put data using jquery

           

          <p>The user's username: <span id='fred1'></span></p>

          <p>The user's jive id: <span id='fred2'></span></p>

          <p>A link containing user parameters: <span id='fred3'></span></p>

           

          The jquery will replace the <span> part. We give each span an id so that we can chose which one to put data into  (eg id='fred1')

           

          2. declare some variables:

           

          var Un = $j("img").attr("data-username");

          var UnID = _jive_effective_user_id;

          var MyUrl = "<a href='http://www.mysurvey.com/?userid=" + _jive_effective_user_id + "&username=" + Un + "'>Take the survey</a>";

           

          3. Use jquery to append text in place of the approriate span id

           

          $j("#fred1").append(Un);

          $j("#fred2").append(UnID);

          $j("#fred3").append(MyUrl);

           

          For example the line:  $j("#fred1").append(Un);  replaces <span id='fred1'></span> with the data stored in variable Un

           

          The full code to use is:

           

          <p>The user's username: <span id='fred1'></span></p>

          <p>The user's jive id: <span id='fred2'></span></p>

          <p>A link containing user parameters: <span id='fred3'></span></p>

          <script>

          var Un = $j("img").attr("data-username");

          var UnID = _jive_effective_user_id;

          var MyUrl = "<a href='http://www.mysurvey.com/?userid=" + _jive_effective_user_id + "&username=" + Un + "'>Take the survey</a>";

          $j("#fred1").append(Un);

          $j("#fred2").append(UnID);

          $j("#fred3").append(MyUrl);

          </script>

            • Re: Embedding a jive user attruibute in an URL in an HTML widget
              dan.lowden

              Im doing something similiar, embedding the code into an HTML widget on the home page of a group. However nothing is happening. Heres the code:

               

              <p>The user's username: <span id='fred1'></span></p>

              <p>The user's jive id: <span id='fred2'></span></p>

              <p>A link containing user parameters: <span id='fred3'></span></p>

               

               

              <script>

              var Un = "username here");

              var UnID = "jiveid here";

              var MyUrl = "a href here";

              $j("#fred1").append(Un);

              $j("#fred2").append(UnID);

              $j("#fred3").append(MyUrl);

              </script>

               

              Chrome throws the following errors;

               

               

              loading resize-me.js 0e94e197631b302083119d64e17c5ed1.js:3

              1. Uncaught ReferenceError: $j is not defined

              Any thoughts?? Im using Jive for teams (SBS 6+)

                • Re: Embedding a jive user attruibute in an URL in an HTML widget
                  milojive

                  You found the small error in my code where I left the </script> off the end

                   

                  I found a small error in yours

                   

                  you put in the following line:   

                   

                  var Un = "username here");

                   

                  you left a ) when you changed the variable value from a function to text

                   

                  It should have read:

                  var Un = "username here";

                   

                  I've tested your code wiht this change it in firefox, ie7 and chrome and it works fine as you can see in the image below

                   

                  Please note you need to be an admin user when you create teh HTML widget adn post in the code. If you are jsut an end used the script wont be activated. This is only for creation it works fine for end users once in place

                   

                  Hope that helps.

                   

                  PS I've corrected my original code

                   

                   

                  clip.bmp