8 Replies Latest reply on Jan 21, 2013 1:31 PM by itriguy

    How to get email from _jive_current_user

      Hey all,

       

      I'm new to this forum and new to Jive development. I've inherited an existing site and we just recently upgraded from 4.5 to 6.1 and it looks like _jive_current_user.email is no longer part of that object. How would I retrieve that information? Also, which documentation would I find info about _jive_current_user and other JS objects. I looked under the JavaScript API docs and didn't see anything in there relating to this.

       

      Thanks in advance,

       

      Jared

        • Re: How to get email from _jive_current_user
          Ryan Rutan

          Jared,

           

          Welcome aboard. =)  So I can confirm that email was removed from this object, in Jive 5.  This is less of an API and more of an artifact that is available for use in the UI.  The Javascript API you are referencing is for building Jive Apps which are a different extension that widgets, etc.. You do have the userID though in that collection, and if needs be you can invoke a REST API call to the GET /people/{userID} service and obtain the email that way.  I hope that helps explain the situation and possibly how to move forward.

           

          Let us know if that doesn't work, or possibly with some more information about the use-case.  Perhaps there's a new way to approach the extension you are inheriting in the new Jive 6 paradigm?

           

          RR

            • Re: How to get email from _jive_current_user

              Hey Ryan,

               

              Thanks for the response. We currently have some forms that allow users to do a submit without having to enter some of their profile info, e.g. email. We depended on the email address for that. I suppose I could do an ajax call, but was hoping to avoid that if there was another way.

               

              Thanks,

               

              Jared

              • Re: How to get email from _jive_current_user

                Hey Ryan,

                 

                I'm trying to add some JS to a page in our Jive instance to retrieve a persons email the way you suggested using the REST API. Is there an example somewhere in the docs that shows how you'd interact with Jive REST services from within a Jive page? I'm assuming I'm already authenticated so is there a simple way to do this?

                 

                Please let me know.

                 

                Jared

                • Re: How to get email from _jive_current_user

                  So I'm trying to accomplish this with the REST api like so:


                  function getEmailAddress(){

                          var userid = window.parent._jive_current_user.ID;

                          var url = window.location.href;

                          var rootUrl = "http://"+window.location.hostname;

                          var restEndPoint = rootUrl + "/people/" + userid;

                          $j.getJSON(restEndPoint,

                                  function(data) {

                                      alert(data);

                                  });

                      };

                      getEmailAddress();

                   

                  But it can't find the restEndPoint. Any other suggestions Ryan Rutan? By the way, I'm using an html widget.

                    • Re: How to get email from _jive_current_user
                      Ryan Rutan

                      Your JS will probably get stripped out unless you are a System Admin.  That's one issue with using the HTML Widget.   You can try using the Managed Snippets Plugin to get you around one issue.  As for the endpoint, try using this:  /api/core/v3/people.    Hope that helps. =)

                      1 person found this helpful
                      • Re: How to get email from _jive_current_user

                        Looks like this did the trick to retrieve the email address. Consuming the result as basic JSON didn't work because of the string ("throw 'allowIllegalResourceCall is false.';"), but once I grabbed removed that I was able to get a JSON object map. I am then iterating over that looking for the 'emails' section and grabbing the first email I find. If anyone knows a better way please let me know, otherwise I'm marking this as the answer to the question.

                         

                        function getEmailAddy(){

                                var userid = window.parent._jive_current_user.ID;

                                var url = window.location.href;

                                var rootUrl = "http://"+window.location.hostname;

                                var restEndPoint = rootUrl + "/api/core/v3/people/" + userid;

                                $j.get(

                                        restEndPoint,

                                        function(data) {

                                            var jsonString = data.replace("throw 'allowIllegalResourceCall is false.';", "");

                                            var json = JSON.parse(jsonString);

                                            $j.each(json, function(i, val) {

                                                if(i == "emails") {

                                                    for (var email in val) {

                                                        emailValue.value = val[email].value;

                                                        break;

                                                    }

                                                }

                                            });

                                        },

                                        "text"

                                );

                            };

                            getEmailAddy();