Orchard - Creating Query Programmatically - module

I am creating a custom module in Orchard. After I enable my module I would like to create a query programmatically.
I do that in my Migrations.cs file thanks to implementation of IDependency interface.
I am able to create the query but I do I programmatically set filters of that query?
var announcementsQuery = _contentManager.Create("Query");
announcementsQuery.As<TitlePart>().Title = "Announcements";
_contentManager.Publish(announcementsQuery);

I found out how to do this:
var announcementsQuery = _contentManager.Create("Query");
announcementsQuery.As<TitlePart>().Title = "Announcements";
announcementsQuery.As<QueryPart>().ContentItem.ContentType = "Announcement";
var filterGroupRecord = new FilterGroupRecord();
var filterRecord = new FilterRecord()
{
Category = "Content",
Type = "ContentTypes",
Description = "Announcement",
Position = 1,
State = "<Form><Description>Announcement</Description><ContentTypes>Announcement</ContentTypes></Form>"
};
filterGroupRecord.Filters.Insert(0, filterRecord);
announcementsQuery.As<QueryPart>().FilterGroups.Insert(0, filterGroupRecord);

Related

how to add Customer Name

$hostedPaymentData = new HostedPaymentData();
$hostedPaymentData->customerEmail = $this->customer_email;
$hostedPaymentData->customerPhoneMobile = $this->customer_mobile_phone;
$hostedPaymentData->addressesMatch = false;
How to add customer name in hosted payment data
The following all work, the comments are the POST variables they populate when requesting the HPP.
// HPP_NAME
$hostedPaymentData->customerName = 'asdf hjkl';
// HPP_CUSTOMER_FIRSTNAME
$hostedPaymentData->customerFirstName = 'asdf';
// HPP_CUSTOMER_LASTNAME
$hostedPaymentData->customerLastName = 'hjkl';

Kentico 13 API SearchHelper.Search returns different object type in .net core than it does in .net mvc

Not sure if anyone has come across this, but currently porting a K13 MVC project over to K13 .Net core (5.0) - both using the same CMS just different Kentico libraries packages but of same hotfix version.
standard Search API functionality being used in both with exact same parameters for a search query but finding that .net core instance will return a TreeNode in its searchResults.Items Data object where the MVC would return its stronglyTyped object
Function
protected ItemsAndCount<News> GetItemsAndCount(string nodeAliasPath, int pageSize = 12, string searchText = "", int currentPage = 0, int category = 0, int year = 0)
{
var culture = LocalizationContext.CurrentCulture.CultureCode;
var defaultCulture = CultureHelper.GetDefaultCultureCode(SiteContext.CurrentSiteName);
var combineWithDefaultCulture = SiteInfoProvider.CombineWithDefaultCulture(SiteContext.CurrentSiteName);
var documentTypes = News.CLASS_NAME;
var docCondition = new DocumentSearchCondition(documentTypes, culture, defaultCulture, combineWithDefaultCulture);
var condition = new SearchCondition(GetExtraConditions(category, year), SearchModeEnum.ExactPhrase, SearchOptionsEnum.NoneSearch, docCondition, false);
var query = ValidationHelper.GetString(searchText, string.Empty);
var path = nodeAliasPath + "/";
var parameters = new SearchParameters
{
Path = path,
SearchFor = SearchSyntaxHelper.CombineSearchCondition(query, condition),
SearchSort = OrderBy,
CurrentCulture = LocalizationContext.CurrentCulture.CultureCode,
DefaultCulture = CultureHelper.GetDefaultCultureCode(SiteContext.CurrentSiteName),
CombineWithDefaultCulture = SiteInfoProvider.CombineWithDefaultCulture(SiteContext.CurrentSiteName),
User = MembershipContext.AuthenticatedUser,
SearchIndexes = SearchIndexHelper.SEARCHINDEX_NEWS,
DisplayResults = pageSize,
StartingPosition = currentPage == 0 ? 0 : (currentPage - 1) * pageSize,
NumberOfProcessedResults = 10000
};
var searchResult = SearchHelper.Search(parameters);
//TotalNoOfRecords = searchResult.TotalNumberOfResults;
return new ItemsAndCount<News>
{
Items = GetItems(searchResult.Items).ToList(),
Count = searchResult.TotalNumberOfResults
};
}
So according to the API docs for SearchHelper, this does look like intended behavior. But you don't actually have to use SearchHelper. You could call the Azure Search client directly and work with the SearchDocument object it returns. An example of this is in the LearningKit for 13.
So this turned out to be an issue due to having all generated code files in a separate library
https://docs.xperience.io/custom-development/adding-custom-assemblies#Addingcustomassemblies-Enablingclassdiscovery
what was throwing me is that all the rest of the site was actually running as expected without this, only searchitems & customtableitems where not returning as strongly typed.

Setting Custom Menu Field values in Rightnow API of Oracle

How to set Custom Menu Field values in Rightnow API of Oracle ?
I have a Custom field of data type Menu like :
Custom field Name : user type
Data Type : Menu
Value can be : Free, Paid or Premium
Can any one send me the java code by solving this problem?
Thanks in Advance
The following link is from the Oracle Service Cloud developer documentation. It has an example of setting a contact custom field using Java and Axis2, which would likely give you most of the information that you need in order to set your custom field.
At a high level, you must create an Incident object and specific the ID of the incident that you want to update. Then, you must create the custom field object structure using generic objects (because each site can have its own unique custom fields). Ultimately, your SOAP envelope will contain the node structure that you build through your java code. Since you're trying to set a menu, the end result is that your custom field is a NamedID object. You'll set the lookup name of the menu to one of the three values that you give above.
I'm a C# guy myself, so my example is in C#, but it should be easy to port to Java using the link above as an example too.
public static void SetMenuTest()
{
Incident incident = new Incident();
incident.ID = new ID();
incident.ID.id = 1234;
incident.ID.idSpecified = true;
GenericField customField = new GenericField();
customField.name = "user_type";
customField.dataType = DataTypeEnum.NAMED_ID;
customField.dataTypeSpecified = true;
customField.DataValue = new DataValue();
customField.DataValue.Items = new object[1];
customField.DataValue.ItemsElementName = new ItemsChoiceType[18]; //18 is a named ID value. Inspect ItemChoiceTypes for values.
customField.DataValue.Items[0] = "Free"; //Or Paid, or Premium
customField.DataValue.ItemsElementName[0] = ItemsChoiceType.NamedIDValue;
GenericObject customFieldsc = new GenericObject();
customFieldsc.GenericFields = new GenericField[1];
customFieldsc.GenericFields[0] = customField;
customFieldsc.ObjectType = new RNObjectType();
customFieldsc.ObjectType.TypeName = "IncidentCustomFieldsc";
GenericField cField = new GenericField();
cField.name = "c";
cField.dataType = DataTypeEnum.OBJECT;
cField.dataTypeSpecified = true;
cField.DataValue = new DataValue();
cField.DataValue.Items = new object[1];
cField.DataValue.Items[0] = customFieldsc;
cField.DataValue.ItemsElementName = new ItemsChoiceType[1];
cField.DataValue.ItemsElementName[0] = ItemsChoiceType.ObjectValue;
incident.CustomFields = new GenericObject();
incident.CustomFields.GenericFields = new GenericField[1];
incident.CustomFields.GenericFields[0] = cField;
incident.CustomFields.ObjectType = new RNObjectType();
incident.CustomFields.ObjectType.TypeName = "IncidentCustomFields";
}

XPages - unsorted Dojo Data Grid opens incorrect document

I'm using a Dojo Data grid together with a REST service to display view data. When I double click on a row, an XPage is opened. My problem is that, if one of the columns in the grid is not sorted, the wrong XPage is opened. What could be the problem here?
<xe:djxDataGrid id="P_Alle_DDG" store="restService2"
styleClass="DojoViewTable" title="Pendenzen - Alle" autoHeight="20"
rowsPerPage="25" selectable="true" selectionMode="multiple"
singleClickEdit="true" rowSelector="2" style="font-size:12pt"
escapeHTMLInData="true">
<xe:this.onRowDblClick><![CDATA[var idx = arguments[0].rowIndex;
var unid = restService2._items[idx].attributes["#unid"];
var url = 'Reparatur.xsp?documentId='+unid+'&action=openDocument';
window.document.location.href = url;]]></xe:this.onRowDblClick>
UPDATE: With the following JavaScript code the problem has been solved:
var grid = arguments[0].grid;
var index = arguments[0].rowIndex;
var item = grid.getItem(index);
var unid = item.attributes["#unid"];
var url = 'Reparatur.xsp?documentId='+unid+'&action=openDocument';
window.document.location.href = url;
Tony, try this method of opening the document. The code if very similar to yours, but the key difference is that I made a view column that contains the unid, I called it "docid". This works for me.
var grid = arguments[0].grid;
var index = arguments[0].rowIndex;
var item = grid.getItem(index);
var unid = item["docid"];
var url = "New_PO.xsp?doc=" + unid;
window.document.location.href = url;

How to use the exported variables of another commonjs module without declare them again?

Suppose I have a module models.js:
exports.User = mongoose.model('User', UserSchema);
exports.Question = mongoose.model('Question', QuestionSchema);
exports.Answer = mongoose.model('Answer', AnswerSchema);
exports.Comment = mongoose.model('Comment', CommentSchema);
Now I want to use it in another file:
var models = require('./models');
var User = models.User;
var Question = models.Question;
var Answer = models.Answer;
var Comment = models.Comment
// then use them
var user = new User();
It is boring that I have to declare all the models I defined in models.js.
Is there any way to simplify it, that I don't need to declare the models again:
var models = require('./models');
// !!! do some magic
var user = new User();
Curious why don't you want to simply do with no magic needed - what is issue with simple ..
var models = require('./models');
var user = new models.User();