I have a property in my index (using the Advanced Database Crawler) for an archive date.
I want to find all items where the date is null or in the future....Date range search will accomplish the second part, but what about the first?
You can't do a null search against Lucene. What I've done in the past is to test for emtpy fields and insert the word "EMPTY" in the index. Then when querying the index you need to add a test that checks for the presence (or absence) of that term. It feels kind of dirty doing it that way but that is the only solution I've been able to find or come up with in the 3 years I've been working with Sitecore and Lucene.
In the DateFieldCrawler class, we modified the following code:
public override string GetValue()
{
if (String.IsNullOrEmpty(_field.Value))
{
return DateTools.DateToString(DateTime.MinValue, DateTools.Resolution.DAY);
}
if (FieldTypeManager.GetField(_field) is DateField)
{
var dateField = new DateField(_field);
if(dateField.DateTime > DateTime.MinValue)
{
return DateTools.DateToString(dateField.DateTime, DateTools.Resolution.DAY);
}
}
return String.Empty;
}
By storing this value, we were able to perform the following queries to include null value dates:
DateRangeSearchParam.DateRange toFirstDate =
new DateRangeSearchParam.DateRange(EVENT_FIRST_DATE,
DateTime.MinValue, toDate.Value);
toFirstDate.InclusiveEnd = false;
eventDates.Add(toFirstDate);
Related
I was wondering if there was a way to add an "Order By" clause when retrieving data from Acumatica through the Web Service API?
IN202500Content IN202500 = oScreen.IN202500GetSchema();
oScreen.IN202500Clear();
Command[] oCmd = new Command[] {IN202500.StockItemSummary.ServiceCommands.EveryInventoryID,
IN202500.StockItemSummary.InventoryID,
IN202500.StockItemSummary.Description,
IN202500.StockItemSummary.ItemStatus,
IN202500.GeneralSettingsItemDefaults.ItemClass,
IN202500.GeneralSettingsItemDefaults.LotSerialClass,
IN202500.PriceCostInfoPriceManagement.DefaultPrice,
};
Filter[] oFilter = new Filter[] {new Filter
{
Field = new Field {ObjectName = IN202500.StockItemSummary.InventoryID.ObjectName,
FieldName = "LastModifiedDateTime"},
Condition = FilterCondition.GreaterOrEqual,
Value = SyncDate
}
};
String[][] sReturn = oScreen.IN202500Export(oCmd, oFilter, iMaxRecords, true, false);
I would like to sort the results for example by DefaultPrice, so that I can retrieve the Top 200 most expensive items in my list (using iMaxRecords = 200 in this case)
I haven't seen any parameters that allows me to do the sorting yet.
I ran into this when I developed a round robin assignment system and the short answer is using the Acumatica API you cant do a sort on the results you have to do it outside of the API (This info came from a friend closely tied to the Acumatica product).
I came up with two options:
Query your DB directly... There are always reasons not to do this but it is much faster than pulling the result from the API and will allow you to bypass the BQL Acumatica uses and write an SQL statement that does EXACTLY what you want providing a result that is easier to work with than the jagged array Acumatica sends.
You can use some Linq and build a second array[][] that is sorted by price and then trim it to the top 200 (You would need all results from Acumatica first).
// This is rough but should get you there.
string[][] MaxPriceList = sReturn.OrderBy(innerArray =>
{
if () // This is a test to make sure the element is not null
{
decimal price;
if (//test decimal is not null))
return price;
}
return price.MaxValue;
}).Take(200).ToArray(); //Take 200 is a shot but might work
Using Grails (or hibernate), I was wanting to know if there is a specific design pattern or method we should be using when implementing a SEARCH of our domain.
For example, on my website, I want to be able to filter(or search) by multiple properties in the domain.
EG: For I have a page which displays a list of HOTELS. When I submit a search form, or if a user clicks "filter by name='blah'", when I enter the controller I get the following:
Domain
String name
String location
Controller
if(params.name && params.reference) {
// Find name/reference
} else if(params.name) {
// Find name
} else if(params.reference) {
// Find reference
} else {
// Find all
}
As you can understand, if there are more properties in the domain to search/filter, the longer the controller gets.
Any help. Please note, I do not want to use the 'searchable' plugin, as this is too complex for my needs.
I would embed these in a named query in the Domain class itself. For example:
Class Hotel {
String name
String city
String country
boolean isNice
static namedQueries = {
customSearch { p ->
if (p?.name) eq('name', p.name)
if (p?.city) eq('name', p.city)
if (p?.country) eq('name', p.country)
if (p?.isNice != null) eq('isNice', p.isNice)
}
}
}
Then later in a controller somewhere ...
def results = Hotel.customSearch(params)
Of course this is a very simple example, but you can expand on it using the same named query or even adding others and chaining them together.
I'm doin a simple query linq to retrieve a label from an optionSet. Looks like the formatted value for the option set is missing. Someone knows why is not getting generated?
Best Regards
Sorry for the unclear post. I discovered the problem, and the reason of the missing key as formattedvalue.
The issue is with the way you retrieve the property. With this query:
var invoiceDetails = from d in xrmService.InvoiceSet
where d.InvoiceId.Value.Equals(invId)
select new
{
name = d.Name,
paymenttermscode = d.PaymentTermsCode
}
I was retrieving the correct int value for the option set, but what i needed was only the text. I changed the query this way:
var invoiceDetails = from d in xrmService.InvoiceSet
where d.InvoiceId.Value.Equals(invId)
select new
{
name = d.Name,
paymenttermscode = d.FormattedValues["paymenttermscode"]
}
In this case I had an error stating that the key was not present. After many attempts, i tried to pass both the key value and the option set text, and that attempt worked just fine.
var invoiceDetails = from d in xrmService.InvoiceSet
where d.InvoiceId.Value.Equals(invId)
select new
{
name = d.Name,
paymenttermscode = d.PaymentTermsCode,
paymenttermscodeValue = d.FormattedValues["paymenttermscode"]
}
My guess is that to retrieve the correct text associated to that option set, in that specific entity, you need to retrieve the int value too.
I hope this will be helpful.
Best Regards
You're question is rather confusing for a couple reasons. I'm going to assume that what you mean when you say you're trying to "retrieve a label from an OptionSet" is that you're attempting to get the Text Value of a particular OptionSetValue and you're not querying the OptionSetMetadata directly to retrieve the actual LocalizedLabels text value. I'm also assuming "formatted value for the option set is missing" is referring to the FormattedValues collection. If these assumptions are correct, I refer you to this: CRM 2011 - Retrieving FormattedValues from joined entity
The option set metadata has to be queried.
Here is an extension method that I wrote:
public static class OrganizationServiceHelper
{
public static string GetOptionSetLabel(this IOrganizationService service, string optionSetName, int optionSetValue)
{
RetrieveOptionSetRequest retrieve = new RetrieveOptionSetRequest
{
Name = optionSetName
};
try
{
RetrieveOptionSetResponse response = (RetrieveOptionSetResponse)service.Execute(retrieve);
OptionSetMetadata metaData = (OptionSetMetadata)response.OptionSetMetadata;
return metaData.Options
.Where(o => o.Value == optionSetValue)
.Select(o => o.Label.UserLocalizedLabel.Label)
.FirstOrDefault();
}
catch { }
return null;
}
}
RetrieveOptionSetRequest and RetrieveOptionSetResponse are on Microsoft.Xrm.Sdk.Messages.
Call it like this:
string label = service.GetOptionSetLabel("wim_continent", 102730000);
If you are going to be querying the same option set multiple times, I recommend that you write a method that returns the OptionSetMetadata instead of the label; then query the OptionSetMetadata locally. Calling the above extension method multiple times will result in the same query being executed over and over.
How does one create a SuiteTalk (NetSuite web api) search query specifying multiple search terms indicating a logical OR operator?
For example, I want to retrieve TimeBill records whose create OR last modified dates are within a particular range. Here's my code that works great for a single search term. Simply adding another search term appears to create a logical AND operation.
/// <summary>
/// Return the list of time bills whose last modified date is within
/// the indicated date range.
/// </summary>
/// <param name="from">Required from date</param>
/// <param name="to">Optional to date</param>
/// <returns>List of time bills</returns>
public IEnumerable<TimeBill> GetTimeBills(DateTime from, DateTime to)
{
_log.Debug(String.Format("Enter TimeBill(DateTime from='{0}', DateTime to='{1}')", from, to));
// Build search criteria.
TimeBillSearch search = new TimeBillSearch();
TimeBillSearchBasic searchBasic = new TimeBillSearchBasic();
SearchDateField searchDateField = new SearchDateField();
searchDateField.#operator = SearchDateFieldOperator.within;
searchDateField.operatorSpecified = true;
searchDateField.searchValue = from;
searchDateField.searchValueSpecified = true;
searchDateField.searchValue2 = to;
searchDateField.searchValue2Specified = true;
searchBasic.dateCreated = searchDateField;
search.basic = searchBasic;
return this.Get<TimeBill>(search);
}
/// <summary>
/// Perform a paged search and convert the returned record to the indicated type.
/// </summary>
private IEnumerable<T> Get<T>(SearchRecord searchRecord)
{
_log.Debug("Enter Get<T>(SearchRecord searchRecord)");
// This is returned.
List<T> list = new List<T>();
// The suitetalk service return this.
SearchResult result = null;
using (ISuiteTalkService service = SuiteTalkFactory.Get<SuiteTalkService>())
{
do
{
// .search returns the first page of data.
if (result == null)
{
result = service.search(searchRecord);
}
else // .searchMore returns the next page(s) of data.
{
result = service.searchMoreWithId(result.searchId, result.pageIndex + 1);
}
if (result.status.isSuccess)
{
foreach (Record record in result.recordList)
{
if (record is T)
{
list.Add((T)Convert.ChangeType(record, typeof(T)));
}
}
}
}
while (result.pageIndex < result.totalPages);
}
return list;
}
Per the NetSuite User Community (forum), I do not believe this is currently possible (at least it does not appear in the WSDL for SuiteTalk/Web Services): https://usergroup.netsuite.com/users/showthread.php?t=29818
However, you can dynamically create a complex Saved Search (using SuiteScript in a Suitelet) that includes AND/OR and parentheses by using the nlobjSearchFilter methods setLeftParens(), setRightParens(), and setOr() (as you surmised, a logical "AND" is the default behavior when multiple filters are present).
A dynamically created Saved Search (confusing terminology here, I know) can also be saved and loaded for later reuse. You could therefore potentially take advantage of dynamically created Saved Searches on the NetSuite server by having your Web Services code invoke a Saved Search and retrieve the results, yet still have everything be dynamic (no hardcoded search filters/values).
As mentioned on the Forum, you could also potentially execute multiple searches and stitch the results together yourself (in your SuiteTalk C#/Java etc. code).
I have a table called "Users" that has a column called "deleted", a boolean indicating that the user is "Deleted" from the system (without actually deleting it, of course).
I also have a lot of tables that have a FK to the Users.user_id column. Subsonic generates (very nicely) the code for all the foreign keys in a similar manner:
public IQueryable<person> user
{
get
{
var repo=user.GetRepo();
return from items in repo.GetAll()
where items.user_id == _user_id
select items;
}
}
Whilst this is good and all, is there a way to generate the code in such a way to always filter out the "Deleted" users too?
In the office here, the only suggestion we can think of is to use a partial class and extend it. This is obviously a pain when there are lots and lots of classes using the User table, not to mention the fact that it's easy to inadvertently use the wrong property (User vs ActiveUser in this example):
public IQueryable<User> ActiveUser
{
get
{
var repo=User.GetRepo();
return from items in repo.GetAll()
where items.user_id == _user_id and items.deleted == 0
select items;
}
}
Any ideas?
You need to change following code in your ActiveRecord.tt file and regenerate your code:
Following is code is located under : #region ' Foreign Keys '
Update: I've updated code for your comment for checking if delete column is available then only apply delete condition.
HasLogicalDelete() - This function will return true if table has "deleted" or "isdeleted" column, false otherwise.
public IQueryable<<#=fk.OtherClass #>> <#=propName #>
{
get
{
var repo=<#=Namespace #>.<#=fk.OtherClass#>.GetRepo();
<#if(tbl.HasLogicalDelete()){#>
return from items in repo.GetAll()
where items.<#=CleanUp(fk.OtherColumn)#> == _<#=CleanUp(fk.ThisColumn)#> && items.deleted == 0
select items;
<#}else{#>
return from items in repo.GetAll()
where items.<#=CleanUp(fk.OtherColumn)#> == _<#=CleanUp(fk.ThisColumn)#>
select items;
<#}#>
}
}
Are you using Subsonic3? If so then you can actually edit the templates to modify the way the Data Access Layer classes are generated.