dynamo Db contains - node.js

I am very new to dynamodb, i got stuck up with a situation here. I am working on a code which is already available here. My requirement is I want to change my query to add a filter.
My current code is
reqObj.TableName = config.storeTableName;
reqObj.FilterExpression = "isActive = :isActive AND isDeleted = :isDeleted AND #state = :stateName",
reqObj.ExpressionAttributeNames = {"#state": "state"};
reqObj.ExpressionAttributeValues= {":isActive": true, ":isDeleted": false , ":city": cityName , ":stateName" : region_code},
I want to check whether a specific value is there in city, i browsed and found out CONTAINS parameter will be suitable. But don't know where to add
Suppose i want to check whether the city contains a value "LOS ANGELES", where the code should be placed in the above code.
will It Be like this
reqObj.TableName = config.storeTableName;
reqObj.FilterExpression = "isActive = :isActive AND isDeleted = :isDeleted AND CONTAINS(city = :city) AND #state = :stateName",
reqObj.ExpressionAttributeNames = {"#state": "state"};
reqObj.ExpressionAttributeValues= {":isActive": true, ":isDeleted": false , ":city": cityName , ":stateName" : region_code},
Thanks

I got it myself, I have to change my query like this
reqObj.FilterExpression = "isActive = :isActive AND isDeleted = :isDeleted AND CONTAINS(city, :city) AND #state = :stateName",
contains, is a function which will have the list of values , with the key value along with it
Thanks

Related

Trying to upsert document in flask_MongoEngine

I've currently got a model:
class Ticket(db.Document):
name = db.StringField #issue.key
project = db.StringField() #issue.fields.project.key
issue_type = db.StringField() #issue.fields.issuetype.name
summary = db.StringField() #issue.fields.summary
description = db.StringField() #issue.fields.description
created = db.DateTimeField() #issue.fields.created
updated = db.DateTimeField() #issue.fields.updated
And some code that attempts to upsert:
Ticket.objects(name=name).update(
upsert = True,
name = name,
project = project,
issue_type = issue_type,
summary = summary,
description = description,
created = created,
updated = updated
)
And I'm getting this error message:
mongoengine.errors.InvalidQueryError: Cannot resolve field "name"
With the relevant bit saying the error occurs in
updated = updated
So far I've tried re-naming the fields of my variables and my model, but the error message remains the same. Sorry for asking if there's an in my face answer I'm blind to.
Update: If I delete name = name from the update it works fine. I renamed name to title and re-added it and it does not work. I am thoroughly confused.
I'm a moron and left off parens on name in the model.

Updating DAC Extension

I am trying to update some custom fields in a DAC extension via code, it is not saving the changes to the DB. The code works fine to retrieve the extension and data. What am I missing - do i have to somehow update the myLS with the extension (i thought it did that automatically)?
myLS = LineItemSerial.Select();
INItemLotSerialExt myext = myLS.GetExtension<INItemLotSerialExt>();
myext.UsrFrame1 = "xyz";
myext.UsrFrame2 = "zzz";
myext.UsrFrame3 = "yyy";
LineItemSerial.Update(myLS);
graph.Actions.PressSave();
You should say to cache of Acumatica that you want to update value:
LineItemSerial.Cache.SetValueExt(myLS , "UsrFrame1", "xyz");
LineItemSerial.Cache.SetValueExt(myLS , "UsrFrame2 ", "zzz");
LineItemSerial.Cache.SetStatus(myLS , PXEntryStatus.Modified);
LineItemSerial.Cache.Update(myLS);
LineItemSerial.Cache.IsDirty = true;
NB. LineItemSerial.Cache.IsDirty = true; for some cases can be omitted but in my experience it was often helpful.
INItemLotSerialExt myext = LineItemSerial.GetExtension<INItemLotSerialExt>(myLS); //if LineItemSerial is a view related to the DAC. I hope LineItemSerial is a public view defined in the graph as you are trying to save the changes when u press the save of graph.
OR
INItemLotSerialExt myext = PXCache<INItemLotSerial>.GetExtension<INItemLotSerialExt>(myLS);
Is'nt this the rite way to get the extension?
From documentation
GetExtension(object)
InventoryItem item = cache.Current as InventoryItem;
InventoryItemExtension itemExt =
cache.GetExtension<InventoryItemExtension>(item);
OR
GetExtension(Table)
The code below gets an extension data record corresponding to the given instance of the base data record.
InventoryItem item = cache.Current as InventoryItem;
InventoryItemExtension itemExt =
PXCache<InventoryItem>.GetExtension<InventoryItemExtension>(item);
Try something like this...
ContractExtension cExt = PXCache<PMProject>.GetExtension<ContractExtension>(project);
ARInvoiceEntry graph = PXGraph.CreateInstance<ARInvoiceEntry>();
graph.Document.Current = graph.Document.Search<ARInvoice.projectID, ARInvoice.docDate>(projectID.Value, invoiceDate.Value);
if(graph.Document.Current !=null)
{
ARInvoice i = graph.Document.Current;
i.InvoiceNbr = cExt.CustomerPO;
graph.Document.Update(i);
graph.Actions.PressSave();
}

Kentico search by classnames

I have a problem with with filtering my search results by ClassNames. Below you can find a code snippet that I use, hope somebody has an idea and can help me.
SearchParameters parameters = new SearchParameters()
{
SearchFor = "support",
SearchSort = "##SCORE##",
Path = "/%",
ClassNames = "cms.faq",
CurrentCulture = "EN-US",
DefaultCulture = CMS.Helpers.CultureHelper.EnglishCulture.IetfLanguageTag,
CombineWithDefaultCulture = false,
CheckPermissions = false,
SearchInAttachments = false,
User = (CMS.Membership.UserInfo)CMS.Membership.MembershipContext.AuthenticatedUser,
SearchIndexes = index.IndexName,
StartingPosition = 0,
DisplayResults = 10,
NumberOfProcessedResults = 10,
NumberOfResults = 0,
AttachmentWhere = String.Empty,
AttachmentOrderBy = String.Empty
};
I could not find any documentation on this, but I suppose the class name should return only data of the type FAQ, but in my case it returns other data to like files, news and custom documents.
I tried also to add something like ClassNames = "+cms.faq" or ClassNames = "##cms.faq##" but had no luck with that :D
Thanks,
Classnames parameter is obsolete and it should not be used anymore. The parameter is still there because of backward compatibility, it was used to filter out search attachments when using SQL search as rocky already mentioned. If you want to filter search results by ClassNames you have to specify the classname righ in SearchFor property like this: +(apple) +classname:[cms.faq TO cms.faq] +_culture:([en-us TO en-us]
I just quickly went through the source code of v8.2 and it seems that the ClassNames parameter is only used to filter out searched attachments. I'm not sure if this is intentional or if it's a bug. I recommend you to contact Kentico support.
The correct format of the ClassNames is a semicolon separated list of page types e.g. CMS.Faq;CMS.News.

mutivalue date field search not working

I have a multivalue field called freeDaysPool which has multiple dates as strings. With the following code, the search does not return anything. If I leave that field out, the search works just fine with the two other fields. I read that I should use CONTAINS with multivalue fields but then I got query not understandable.
I've tried the back-end field as a date field and as a text field and tested all kinds of query combinations and date formats but no luck. Any help is really appreciated.
This is the search button code:
var query = new Array("");
var cTerms = 0;
// Field 1
var search01 = getComponent("searchcustomReservationField01").getValue();
if (#Contains(#Text(search01),"any city")){"";}
else {query[cTerms++] = '[customReservationField01]="' + search01 +'"'};
// Field 2
var search02 = getComponent("searchcustomReservationField02").getValue();
if (#Contains(#Text(search02),"any city")){"";}
else {query[cTerms++] = '[customReservationField02]="' + search02 + '"'};
// Date 1
var formatter = new java.text.SimpleDateFormat("d.M.yyyy");
query[cTerms++] = 'FIELD freeDaysPool = ' + formatter.format(getComponent("searchcustomDateField01").getValue());
// if query is still empty, we fill it with asterisk
if(query == "" || query == null){
query[cTerms++] = "*";
}
// make all as string
qstring = query.join(" AND ").trim();
sessionScope.searchString = qstring;
It will return query as:
[customReservationField01]="Oslo" AND [customReservationField02]="Oslo" AND FIELD freeDaysPool = 6.2.2015
AFAIK date values in formulas (and a query is a formula) have to be noted like
[06.02.2015]
to compare them. Just try to use your formular in the Notes Client to do a fulltext search. If you get results and no errors you found the correct format. That's at least the way I test queries as I'm not able to remind the syntax for years :-D
Thank you for all the help! Seems that Domino keeps the field type as date field even if you change it back to text field (noticed that from the notes FTsearch). I created completely new text field and added the days as strings in dd.MM.yyyy format. I also search them as strings and it works fine.
The changed code bit now looks like this:
// Date 1
var formatter = new java.text.SimpleDateFormat("dd.MM.yyyy");
query[cTerms++] = '[freeDays] CONTAINS "' + formatter.format(getComponent("searchcustomDateField01").getValue())+'"';

create a filter not a group filter

I am creating a custom module in Orchard , I would like to create a query programmatically.
string queryName= "Product";
var item = _orchardServices.ContentManager.New("Query");
item.As<TitlePart>().Title =queryName;
_orchardServices.ContentManager.Create(item, VersionOptions.Draft);
if (!item.Has<IPublishingControlAspect>() && !item.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable)
_orchardServices.ContentManager.Publish(item);
var queryPart = item.As<QueryPart>();
queryPart.ContentItem.ContentType = queryName;
string desc =" filter for the query";
string contentType = "CommonPart.ChannelID.";
var filterGroupRecord = new FilterGroupRecord();
var filterRecord = new FilterRecord()
{
Category = "CommonPartContentFields",
Type = contentType,
Position = 0,
};
filterRecord.State = "<Form><Description>" + desc + "</Description><Operator>Equals</Operator><Value>ChannelId</Value></Form>";
filterGroupRecord.Filters.Add(filterRecord);
queryPart.FilterGroups.Insert(0, filterGroupRecord);
the problem is that:I want set a filters of the query,not a filters group.
could you tell me how to improve my code?
Database structure and class declarations make it impossible. Why do you need it?
Update:
I means that you must use FilterGroupRecord at least one.
But when Query published that Filter Group will be created automatically if query have not yet Filter Group (see at QueryPartHandler). You should add your filters to this group. And not needed to create new group.
var existingFilterGroup = queryPart.FilterGroups[0];
existingFilterGroup.Filters.Add(filterRecord);
Update 2:
To avoid problems with draftable query (and several other potential problems Orchard CMS: Adding default data to fields and then querying them) it is better to move the calling Publish method to the end of your code and other part of your code should be left unchanged. And in your case would be better if you will always publish your query without checking IPublishingControlAspect and Draftable.

Resources