Answers.Body: <p>To get the 'groups' result from the returned 'result' - I had to access the nested data. I referenced this great explanation here: <a href="https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json">https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json</a></p>
  
  <p>I still struggled for a bit and realized that's because the groups result i was looking for was nested down two levels.</p>
  
  <pre><code>result Object { is_error: 0, version: 3, count: 1, id: 68525, values: Object }
  
     values Object { 68525: Object }
  
         68525 Object { contact_id: "68525", groups: "Administrators", id: "68525" }
  </code></pre>
  
  <p>On top of that to reference that last object by a number i had to enclose on quotes.</p>
  
  <p>I still have work to do towards my ultimate functionality but my proof of concept holds true.</p>
  
  <p>Here's what I ultimately used to get the contents of 'groups':</p>
  
  <pre><code>console.log(result['values']['68525']['groups']);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-05T12:40:47.393Z
Answers.LastActivityDate: 2017-10-05T12:40:47.393Z
Answers.UserDisplayName: RayWright
Body: <p>Through javascript, I was hoping to check what groups a user belongs to and then use that information to show / hide something. I can't use ACLs because I'd like the average internal user to be able to enter the information on intake but not be able to edit it in future.</p>
  
  <p>Using the API, I can get an object that has a</p>
  
  <pre><code>    CRM.api3('Contact', 'get', {
    "return": "group",
    "id": 68525 // arbitrary number will need current user
  }).done(function(result) {
    // do something
      console.log(result);
  
  });
  </code></pre>
  
  <p>which returns this</p>
  
  <pre><code>Object { is_error: 0, version: 3, count: 1, id: 68525, values: Object }
  </code></pre>
  
  <p>The group info <strong>is in</strong> the values: Objects, how can I reference it?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-04T19:13:49.073Z
Comments.Text: Did you try console.log(result.values); ?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-04T19:18:38.887Z
Comments.Text: Similar result: Object { 68525: Object } In the console I can see inside that nested object, it holds the groups info, I just have no idea how to get to it.
Comments.UserDisplayName: RayWright
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-04T20:08:40.410Z
Comments.Text: You can also iterate with a loop if you don't know the id, e.g. for (var i in result.values) { // do something with result.values[i] } Can also search the internet for general javascript howtos.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-05T12:34:10.590Z
Comments.Text: Yes, I did search the internet, but was struggling for the right search terms, I thought perhaps someone here had done something similar and could offer advice. I figured it out for myself.
Comments.UserDisplayName: RayWright
Tags: <api><javascript>
Title: Javascript Contact API - how do I 'do something' with results
ThreadText: # Javascript Contact API - how do I 'do something' with results
  
  (Asked by: username_0 on 2017-10-04)
  
  Through javascript, I was hoping to check what groups a user belongs to and then use that information to show / hide something. I can't use ACLs because I'd like the average internal user to be able to enter the information on intake but not be able to edit it in future.
  Using the API, I can get an object that has a
      CRM.api3('Contact', 'get', {
    "return": "group",
    "id": 68525 // arbitrary number will need current user
  }).done(function(result) {
    // do something
      console.log(result);
  
  });
  
  which returns this
  Object { is_error: 0, version: 3, count: 1, id: 68525, values: Object }
  
  The group info is in the values: Objects, how can I reference it?
  
  **Tags:** api, javascript
  
  > **Comments:**
  > **username_1**: Did you try console.log(result.values); ?  
  > **username_0**: Similar result: Object { 68525: Object } In the console I can see inside that nested object, it holds the groups info, I just have no idea how to get to it.  
  > **username_1**: You can also iterate with a loop if you don't know the id, e.g. for (var i in result.values) { // do something with result.values[i] } Can also search the internet for general javascript howtos.  
  > **username_0**: Yes, I did search the internet, but was struggling for the right search terms, I thought perhaps someone here had done something similar and could offer advice. I figured it out for myself.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-10-05. Score: 1 | Accepted answer
  
  To get the 'groups' result from the returned 'result' - I had to access the nested data. I referenced this great explanation here: https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json
  I still struggled for a bit and realized that's because the groups result i was looking for was nested down two levels.
  result Object { is_error: 0, version: 3, count: 1, id: 68525, values: Object }
  
     values Object { 68525: Object }
  
         68525 Object { contact_id: "68525", groups: "Administrators", id: "68525" }
  
  On top of that to reference that last object by a number i had to enclose on quotes.
  I still have work to do towards my ultimate functionality but my proof of concept holds true.
  Here's what I ultimately used to get the contents of 'groups':
  console.log(result['values']['68525']['groups']);
  
  
  ---
  
  