Exception when using Projection with DynamicQuery in liferay 6.1? - liferay

Since when edit a web content, liferay automatically creates new version of an article, I want to get the latest version of a specific article. I used the dynamic query as follows:
DynamicQuery query = DynamicQueryFactoryUtil.forClass(JournalArticle.class, PortletClassLoaderUtil.getClassLoader());
query.setProjection(ProjectionFactoryUtil.max("version"));
List<JournalArticle> jList = (List<JournalArticle>)JournalArticleLocalServiceUtil.dynamicQuery(query);
I searched on google and notice ProjectionFactoryUtil.max("version") was used a lot. But in my case, exceptions have thrown:
"java.lang.Double cannot be cast to com.liferay.portlet.journal.model.JournalArticle"
Am I missing something?

Use of ProjectionFactoryUtil.max("version") in DynamicQuery will return double value which will be maximum of field 'version'. You are trying to cast double type value to JournalArticle thats why facing this exception.
HTH
Sent from mobile.

As for the intent of getting the latest version of a JournalArticle: JournalArticleLocalServiceUtil has an API method fetchLatestArticle (with a few varying parameter sets, for example to prefer published articles over non-published).
In Liferay 5.x it's called getLatestArticle.

Related

Customize search results and facets in Liferay 7.1

this is my first question, thanks in advance.
I am trying to customize the liferay results portlet and facets, with custom results. I need to filter the results once the search is launched, and remove the results that do not have layoutId :
with->
layoutIds = journalContentSearchLocalService.getLayoutIds(groupId,false,articleIdResult);
I´m doing this in a jsp fragment, but i think that it´s not correct.
I have been searching and i think the correct way is to modify the java class with the action, for example with acction coomand hook, is this correct?
Please, can you explain me the correct way to modify this functionalities?
Regards!!
ok. it looks you want result of journalarticle having display page is set. in that case, you need to look for JournalarticleModelPreFiltercontributor component extension or journalarticlepostprocessor if you are using legacy search api. when article gets indexed layoutuuid field is also indexed for each article. that field will have value if display page is set for specific web content or article.
So, you can use any of the above mentioned way to add check that this field should not be empty as search term. which will filter your result in request itself. instead adding overhead on result as later filtering in jsp.

How to fix ClassCastException when using localized n-m relations with Smartedit?

In Hybris 6.7.0, using I have a component that contains a localized list of another component.
I have been able to implement this using a n-m localized relationtype to implement a localized list that contains the component.
It works perfectly in CMS cockpit. However, in smartedit, it causes a ClassCastException.
The default converter seems to fail to recognize the collection type and therefore trying to cast the collection to a item model which causes the error.
Is there anyway to implement a localized collection that won't causes the exception in SmartEdit?
I have tried using a map and collection pair for the localization instead of a localized relation but the same problem occurred.
2019-3-7 - Updates: After a series of trial and error, I have realized that the LocalizedCollection will never be called because all localized attribute in Hybris is stored with an item type of MapType, which does not trigger the localizedCollection getter as it check if the localized attributs is of type CollectionType.
It seems to be a bug on SAP side. I am currently trying to come up with a temporary fix for the problem.

What is the internal id(name/number) for a saved search record type?

I created a savedSearch for a savedSearch itself via UI with an internal id customsearch_savedsearch.
When I'm loading the search using a suiteScript. It shows me an Unexpected error has occured.
var search = nlapiLoadSearch(null, 'customsearch_savedsearch');
The above statement works fine for all other record-types, But fails for a savedSearch record type.
What could be the internal id for the savedSearch record type?
You cannot use null for the first parameter. When loading or creating a search, you must specify the record type for the search as well. Whatever record type customsearch_savedsearch searches for, that's what you would pass in as the first parameter.
So for instance if your saved search is a Customer search, then you would load it by:
var search = nlapiLoadSearch('customer', 'customsearch_savedsearch');
Try
var search = nlapiSearchRecord(null, 'customsearch_savedsearch');
Documentation:
nlapiSearchRecord(type, id, filters, columns)
Performs a search using a set of criteria (your search filters) and columns (the results). Alternatively, you can use this API to execute an existing saved search. Results are limited to 1000 rows. Also note that in search/lookup operations, long text fields are truncated at 4,000 characters. Usage metering allowed for nlapiSearchRecord is 10 units.
This API is supported in client, user event, scheduled, portlet, and Suitelet scripts.
If `
var search = nlapiSearchRecord(null, 'customsearch_savedsearch');
does not work`use
var search = nlapiSearchRecord('', 'customsearch_savedsearch');
Everything looks correct in your statement. I think the problem is that SuiteScript does not support SavedSearch record types. Here is a list of supported types.
You should be able to run this using the above mentioned
var search = nlapiSearchRecord(null, 'customsearch_savedsearch',null,null);
I've used this in my code and haven't had any issues. Make sure you have the right permissions set on the saved search. To start with, set it as Public. And in the Audience, "select all" roles.
Your syntax is correct. However, Saved Search type (also like Budget record) is not scriptable even you are able to create a saved search. That is why you encountered that error. Most likely, those record types listed on the SuiteScript Record Browser are supported. You may check the list here:
***Note: You should log in first to the account..
Production: https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/script/record/account.html
Sandbox: https://system.sandbox.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/script/record/account.html
I know this is a bit of an old question, and I came across it in my own attempt to do the same, but I just tried the following with success:
var search = nlapiLoadSearch('savedsearch', 'customsearch_savedsearch');
Seemed a little on the nose, but it did the trick.

Accessing fields on DriverResult Editor POST in Orchard CMS 1.7

crosspost: https://orchard.codeplex.com/discussions/473252
When updating Content Items back in 1.6, I was able to get field values on POST from the HttpContext like below:
var lat = HttpContext.Current.Request["Latitude"];
Ever since 1.7, those return null and upon inspecting the request, it doesn't have those properties. I checked some more and couldn't find the fields anymore. I even tried injecting the IHttpContextAccessor but still nothing.
Does anyone know where they are held now?
Any piece of advise or information would be highly appreciated, thanks!
Do not access post data directly. Use model binding instead. This can be done either with specifically typed and named parameters on a controller action, or through the TryUpdateModel method that is available from driver post methods.

Get a Web-content article with a specific Structure in Liferay

I have started developing portlets with Liferay and I would like to show one (or more) Web-content article(s) with a specified structure.
For example, suppose I've a structure "A" so how can I get the last web-content article which is created using this structure?
This article explains how to get articles with a tag but not with a structure.
Thank you
The Liferay API Docs (this is for 6.1, as I don't know what version you're using) are your friend as is the Liferay source code.
In short you'll want to use one of the following API methods:
JournalArticleLocalServiceUtil.getStructureArticles(long groupId, String structureId);
JournalArticleLocalServiceUtil.getStructureArticles(long groupId, String structureId, int start, int end, OrderByComparator obc)
These rely on knowing the ID of the structure from which your content was generated, if you don't know what it is then you can use the following API method to get a list of all of them for your current Community:
JournalStructureLocalServiceUtil.getStructures(long groupId)
You can also use similar methods to find Journal Articles by the JournalTemplate that they use:
JournalTemplateLocalServiceUtil.getStructureTemplates(long groupId, String structureId);
JournalArticleLocalServiceUtil.getTemplateArticles(long groupId, String templateId);
JournalArticleLocalServiceUtil.getTemplateArticles(long groupId, String templateId, int start, int end, OrderByComparator obc)
Comment back if you have any questions, or if this answers your question please hit the "Accept answer" button tick! Thanks!

Resources