For loop across all available companies? - axapta

I need to create a job with a for loop (I think) that goes through all available companies and checks for a specific value. I'm just not familiar with how I would get it to select each individual company.
Does anyone know the syntax for that?

I use the following technique in a job:
static void CountIt(Args _args)
{
DataArea DataArea;
void doIt()
{;
info(int2str((select Count(RecId) from CustTable).RecId));
}
setPrefix("Counting");
while select DataArea where !DataArea.isVirtual
{
print(DataArea.Id);
setPrefix(DataArea.Id);
changecompany (DataArea.Id)
{
doIt();
}
}
}

Please bear in mind to reset your table variables in the changecompany scope, otherwise you will get strange or no result at all.
A colleague was to do a task as yours and he got absolutely no results for the code inside the changecompany scope. I googled and found this blogpost: http://dynamics-ax-live.blogspot.se/2011/10/what-not-to-forget-when-using.html

The functionality you're looking for is called "Cross Company" data access. MSDN has a great bit of code samples here:
X++ code:
http://msdn.microsoft.com/en-us/library/cc518738.aspx
Main article:
http://msdn.microsoft.com/en-us/library/cc634544.aspx

Related

Axon Framework: Delete Aggregate Root

I honestly have no idea where to begin. The repository aspect is relatively simple but I cannot seem to find any information on how to delete an aggregate root via the CommandGateway.
Any directions and/or documentation on how to achieve this would be greatly appreciated.
Putting this here for future reference for anyone else that might be as lost as I was initially.
When using the Event Sourcing Aggregate, one can make use of the markDeleted() static method on the Aggregate in question. I placed mine in the #EventSourcingHandler
import static org.axonframework.modelling.command.AggregateLifecycle.markDeleted;
#EventSourcingHandler
public void on(DeletedEvent event){
markDeleted();
}
Further information can be found at: https://docs.axoniq.io/reference-guide/implementing-domain-logic/command-handling/aggregate#aggregate-lifecycle-operations
To delete the view data associated with the aggregate I used an external #EventHandler:
#EventHandler
public void on(DeletedEvent event, ReplayStatus status){
entityRepo.deleteById(event.getId());
}
Thanks to Allard for engaging me in the comments section.

Why is there no static QDir::makepath()?

I know, that to create a new path in Qt from a given absolute path, you use QDir::makepath() as dir.makepath(path), as it is suggested in this question. I do not have any trouble in using it and it works fine. My question is directed, as to why the developers would not provide a static function to call in a way like QDir::makepath("/Users/me/somepath/");. Needing to create a new QDir instance seems unnecessary to me.
I can only think of two possible reasons:
1. The developers were "lazy" or did not have time so they did not add one as it is not absolutely necessary.
2. The instance of QDir on which mkpath(path) is called, will be set to path as well, so it would be convenient for further usage - but I can not seem to find any hints that this is the actual behaviour within the docs.
I know I repeat myself, but again, I do not need help as of how to do it, but I am much interested as of why one has to do it that way.
Thanks for any reason I might have missed.
Let's have a look at the code of said method:
bool QDir::mkdir(const QString &dirName) const
{
const QDirPrivate* d = d_ptr.constData();
if (dirName.isEmpty()) {
qWarning("QDir::mkdir: Empty or null file name");
return false;
}
QString fn = filePath(dirName);
if (d->fileEngine.isNull())
return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false);
return d->fileEngine->mkdir(fn, false);
}
Source: http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/io/qdir.cpp#n1381
As we can see, a static version would be simple to implement:
bool QDir::mkdir(const QString &dirName) const
{
if (dirName.isEmpty()) {
qWarning("QDir::mkdir: Empty or null file name");
return false;
}
return QFileSystemEngine::createDirectory(QFileSystemEntry(dirName), false);
}
(see also http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/io/qdir.cpp#n681)
First, the non-static method comes with a few advantages. Obviously there is something to using the object's existing file engine. But also, I would imagine the use-case of creating several directories under a specific directory (that the QDir already points to).
So why not provide both?
Verdict (tl/dr): I think the reason is simple code hygiene. When you use the API, the difference between QDir::makepath(path); and QDir().makepath(path); is slim. The performance hit of creating the object is also negligible, as you would reuse the same object if you happen to perform the operation more often. But on the side of the code maintainers, it is arguably much more convenient (less work and less error prone) to not maintain two versions of the same method.

Why does simple logic crash my arduino code?

I have found that my arduino app will crash if I use the following logic:
if (boolA && boolB) {
doSomething();
}
In a simple program it will work, but with a sufficiently large project, I find I have to change the above to:
if (boolA) {
if (boolB) {
doSomething();
}
}
In a number of projects I have tracked the cause to this logic.
If you want to check memory, you can do so by using Available Memory.
And here I put those files into a library you can use more easily: Avalaible Memory Lib
Although, actual code would be better to try to solve your problem...
You many need to use the long hand syntax like,
if (boolA==HIGH && boolB ==HIGH) {
doSomething();
}
This may also help:
http://forum.arduino.cc/index.php/topic,43588.0.html

Asynchronous Callback in GWT - why final?

I am developing an application in GWT as my Bachelor's Thesis and I am fairly new to this. I have researched asynchronous callbacks on the internet. What I want to do is this: I want to handle the login of a user and display different data if they are an admin or a plain user.
My call looks like this:
serverCall.isAdmin(new AsyncCallback<Boolean>() {
public void onFailure(Throwable caught) {
//display error
}
public void onSuccess(Boolean admin) {
if (!admin){
//do something
}
else{
//do something else
}
}
});
Now, the code examples I have seen handle the data in the //do something// part directly. We discussed this with the person who is supervising me and I had the idea that I could fire an event upon success and when this event is fired load the page accordingly. Is this a good idea? Or should I stick with loading everything in the inner function? What confuses me about async callbacks is the fact that I can only use final variables inside the onSuccess function so I would rather not handle things in there - insight would be appreciated.
Thanks!
Since the inner-class/ anonymous function it is generated at runtime it needs a static memory reference to the variables it accesses. Putting final to a variable makes its memory address static, putting it to a safe memory region. The same happens if you reference a class field.
Its just standard java why you can only use Final variables inside an inner-class. Here is a great discussion discussing this topic.
When I use the AsyncCallback I do exactly what you suggested, I fire an event though GWT's EventBus. This allows several different parts of my application to respond when a user does log in.

Best Practices for Building a Search App? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I will be starting a simple datastore-and-search project soon. Basically, one of those "put my huge Excel spreadsheet into a database, build a web GUI for it, and make it searchable" type-things.
One thing that's been bugging me is the actual search logic that will be used when the user enters some criteria. I am imagining a search interface with a text field, and a few other filtering tools - drop down combo boxes and check boxes and such.
While that gives me very strong, granular control over the filtering I can perform, I am wondering what SO's thoughts are on actually performing the search. I'll be using ASP.NET, MS SQL Server, and Linq-To-SQL here, so keep those technologies in mind.
Off the top of my head, I think I'd do something like:
var results = from s in db.Stuff
where (s.Prop1.Contains(textFilter) ||
s.Prop2.Contains(textFilter) ||
s.Prop3.Contains(textFilter)) &&
checkbox1.IsChecked ?
s.Prop4.ToLower().Equals(combobox1.Text) : true
select s;
Here's what I know:
How to do grouping and joins if necessary
I can use the Contains() method on individual properties to generate SQL LIKE queries
I can filter things property-by-property, building my search logic as above.
Here's what I'm asking:
Is there a way to search all properties (without pulling all objects into memory - which I assume means building a list of each object's properties with reflection, stringifying them, and then checking is out)? If not, this seems incredibly cumbersome as I'd have to build new logic for every new property I might add. Something like s.Contains(textFilter) in the above would be ideal.
How does a SQL LIKE query actually work? Is that something I want to do?
Is there a standard way of implementing search rules such as quoted strings for full-matching and logical operators such as AND and OR? I would be surprised if every application that implemented them did so with custom parsing logic.
Am I barking up the wrong tree? Did I miss something?
I had to create a similar search for a comments system recently. What I did was I created some extension methods off of the comments which allowed me to pass in a generic filtering object.
Here is the sample code that I used:
This is just a partial method and does not have the return but it will give you a picture of what I am doing:
public List<oComment> GetComments(oCommentSearch filters)
{
using (CommentDataContext db = CommentContextFactory.CreateContext())
{
var query = from comment in db.COMMENTs.FilterComments(filters)
select comment;
}
}
As you can see off the COMMENTs i have FilterComments. This is an extension method. This method looks like this (this is the entire class I have):
public static class CommentExtensions
{
public static IQueryable<COMMENT> FilterComments(this IQueryable<COMMENT> Comments, oCommentSearch Filters)
{
Filters = CheckFilter(Filters);
IQueryable<COMMENT> tempResult = Comments;
if(Filters.Classes.Count() > 0)
{
tempResult = from t in tempResult
where
Filters.Classes.Contains(t.CLASS_ID)
select t;
}
if (Filters.Flags.Count() > 0)
{
tempResult = from t in tempResult
where
Filters.Flags.Contains((int) t.FLAG_ID)
select t;
}
if (Filters.Types.Count() > 0)
{
tempResult = from t in tempResult
where
Filters.Types.Contains(t.CommentTypeId)
select t;
}
return tempResult;
}
private static oCommentSearch CheckFilter(oCommentSearch Filters)
{
Filters.Classes = CheckIntArray(Filters.Classes);
Filters.Flags = CheckIntArray(Filters.Flags) ;
Filters.Types = CheckIntArray(Filters.Types) ;
return Filters;
}
private static int[] CheckIntArray(int[] ArrayToCheck)
{
return ArrayToCheck == null || ArrayToCheck.Count() == 0 ? new int[] {} : ArrayToCheck;
}
}
This should get you started in the right direction for what you are trying to do.
Hope this helps!
You didn't mention it in your list of technologies that you're using, but don't overlook using Lucene.NET. It does searching very well and is fairly easy to setup. Basically, you add documents to an index, and Lucene efficiently manages the index. That way, you can search the index instead of loading documents one by one and looking at their properties.
Is there a way to search all properties (without pulling all objects into memory - which I assume means building a list of each object's properties with reflection, stringifying them, and then checking is out)? If not, this seems incredibly cumbersome as I'd have to build new logic for every new property I might add. Something like s.Contains(textFilter) in the above would be ideal.
We are using MsSql full text search functionality for this.

Resources