getCustomField() on a Blog

I’m trying to use: cb.getCustomField(“mainimage”,” ”) on a blog. But it is throwing an error.

Application Execution Exception

Error Type: ContentBox.CBHelper.InvalidEntryContext : [N/A]
Error Messages: Entry not found in collection
This probably means you are trying to use the entry in an non-entry page

Is there some other way that you’re supposed to get this? It says in the blog entry editor that we are to use cb.getCustomField() but doesn’t seem to be working.

Please advise.

Marco G. Williams

Information Technology Manager

Global Electronic Technology

949.380.0345 x209

Are you sure the name of custom field is correct?

Yeah… It is… I figured out what the problem was. I don’t know if this is a bug or not.

If your trying to access a customField from /blog the main page where the “list” of entries are then the value is not available in the entry template.

It thinks that you are on the wrong view, I think. So the method getCustomField which calls getCurrentCustomFields; This method has a bit of code as follows:

if( isPageView() ){

fields = getCurrentPage().getCustomFields();

}

else{

fields = getCurrentEntry().getCustomFields();

}

The view for /blog falls within the IsPageView ( from what I can tell ), I’m still a little fuzzy on which view were actually in and I didn’t debug further.

However, to resolve the problem. I used the following code in my entry template.

fields = entry.getCustomFields();

customFields = {};

for(thisField in fields){

customFields[ thisField.getKey() ] = thisField.getValue();

}

Since I’m accessing this from within the Entry template, I am able to acquire the CustomFiles by doing the above. Then I can check my variable customFields for the key and display the value.

Thanks and hope this helps someone else at somepoint.

Marco G. Williams

Information Technology Manager

Global Electronic Technology

949.380.0345 x209

Yeah… It is… I figured out what the problem was. I don’t know if this is a bug or not.

If your trying to access a customField from /blog the main page where the “list” of entries are then the value is not available in the entry template.

It thinks that you are on the wrong view, I think. So the method getCustomField which calls getCurrentCustomFields; This method has a bit of code as follows:

if( isPageView() ){

fields = getCurrentPage().getCustomFields();

}

else{

fields = getCurrentEntry().getCustomFields();

}

The view for /blog falls within the IsPageView ( from what I can tell ), I’m still a little fuzzy on which view were actually in and I didn’t debug further.

However, to resolve the problem. I used the following code in my entry template.

fields = entry.getCustomFields();

customFields = {};

for(thisField in fields){

customFields[ thisField.getKey() ] = thisField.getValue();

}

Since I’m accessing this from within the Entry template, I am able to acquire the CustomFiles by doing the above. Then I can check my variable customFields for the key and display the value.

Thanks and hope this helps someone else at somepoint.

Marco G. Williams

Information Technology Manager

Global Electronic Technology

949.380.0345 x209

Brad,

I have run into this issue as well, the time this one bites me the most, is when I am using a custom view and try to preview the entry from the Entry Editor in the dashboard.

I also did something similar, but don’t recall the fix that I did.