3 Replies Latest reply on Oct 17, 2013 11:42 AM by maxime.duval@lacapitale.com

    Embedding a jive user attribute 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 attribute 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);