Issues retreiving Prismic data by key

I’m trying to retrieve several data points from a Prismic document. All but one of them are giving me no issues. There is 1 data key that is returning null. I’m doing the same exact thing I’m doing for all of the others. I created a couple of dummy variables for testing:

/* This one pulls in the whole first item in the group with no issue */
var testGroup = /*[[${document.getGroup(document.getType() + '.group').getDocs()[0]}]]*/ null;

/* This one gets the 'time' element from the first group and works with no issues*/
var goalTime = /*[[${document.getGroup(document.getType() + '.group').getDocs()[0].getText('time')}]]*/ 2;

/* This one returns null when there is clearly a value in the document */
var testLine = /*[[${document.getGroup(document.getType() + '.group').getDocs()[0].getText('line_number__0_no_line__1_under__2_between__3_above_')]}]]*/ 2;

So I did a little playing around in the Chrome console, and I was able to access the variable testGroup. In there, I was able to see the value for my key that I was trying to get… so it IS in there:

Chrome console showing data value

In the console, I was successfully able to retrieve the value using:

testGroup['fragments']['line_number__0_no_line__1_under__2_between__3_above_']['value']

So, although a little hacky and not the way I wanted to do it, I then tried:

var testLine2 = /*[[${document.getGroup(document.getType() + '.group').getDocs()[0]['fragments']['line_number__0_no_line__1_under__2_between__3_above_']['value']}]]*/ 2;

But I once again got a null reference error. This isn’t making any sense to me… any ideas?

Thanks!

Hello Jesse, welcome to the community forum!

If you could provide us with more information we’ll be happy to help you out:

  • I can see that you were trying to preview the data coming from the endpoint. What else were you trying to do in the console?
  • Which technology are you using?
  • If you think this error comes from an empty field inside one of the documents in your repository you can always check if this is the case by going to the API browser of your repo: https://your-repo-name.prismic.io.

Thank you for your response :slight_smile:

I was only using the console to try to find where my data was within my document, and to make sure it was there. I am able to see the group and the data I’m trying to retrieve. In the screenshot of the console that I posted, on the line that I hightlighted, I can see that the data key is there in the document with a value of 2 in this example. For some reason, I’m having issues accessing that value. I can access it through the console, but not in my javascript.

I am using Thymeleaf with Spring and Java for the server side. I am getting the document in my Java code, then sending the entire document to the client and navigating through it in my javascript code.

I’m fairly new to this project and these technologies, so I’m sorry if my details are a little vague. If you need more information, I will try to find out the answers.

Thanks!

Hi Jesse,

This is Fares from the education team, I had a look at your code and I have noticed that you an extra bracket the code

can you try this instead?

   var testLine = [
	[$ {
        document.getGroup(document.getType() + '.group').getDocs()[0].getText('line_number__0_no_line__1_under__2_between__3_above_')
	}]
]

Please let me know if that doesn’t solve the issue so that we do further debuging,
Best

Oh my goodness, thanks so much!

1 Like