How to apply SetFilter in a query object in while loop body after query.open() in AL Business Central - dynamics-business-central

I just want to apply another filter while we are in the body of query during reading it.
For Example: Here is my code.
customAttributeQuery.SetFilter(Value_ID, attributeValueID);
customAttributeQuery.Open();
while customAttributeQuery.Read() do begin
counter := 0;
// HERE IN BODY I WANT TO APPLY ANOTHER FILTER
// customAttributeQuery.SetFilter(Value, attributeValue);
end;
The issue is when i apply another filter in the body of while loop and open the query and try to read it .This code always breaks my whole code.

I'm pretty sure you cannot do that, if you apply a filter, most probably you break the loop and jump out. Try to incorporate your filter inside the Query Object if possible, to that extent you can use something like:
Table 1 as t1
{
Table 2 a t2
{
Table 1 as t3
{}
}
}
if you use this correctly, by setting a filter on t2, you get your desired filter on t3, which is pointing to the Table in the t1 loop.

Related

Need to reverse a repeat region

I have a firebase element that is pulling in the last 5 items
<firebase-element id="base" location="https://mydb.firebaseio.com/mydata" data="{{items}}" keys="{{keys}}" limit="5" ></firebase-element>
That is bound to this repeat region
<template repeat="{{id in keys}}">
<x-chat-list id="chatList" username="{{items[id]['uuid']}}" text="{{items[id]['text']}}" ></x-chat-list>
</template>
I simply need to reverse the order of the repeat region.
I think you just need to observe the array and reverse it (or store the reversed values in another attribute)
Ex :
keysChanged : function() { this.keys.reverse(); }
If the firebase-element sometimes changed the values in the array without triggering the keysChanged function, you can also use the observe object
Just add a custom Polymer expression, e.g.:
PolymerExpressions.prototype.revArray = function(a) {
return a.reverse();
}
and pipe your data to it:
<template repeat="{{id in keys | revArray}}">
Now you can use this anywhere since the expression handler is global.

How to check specific column exist in datarow?

I came across situation,where columnname for datatable is dynamic.While fetching a data I want to check existence of column.
DataTable table = ds.Table["Sample1"]
if(table.Row.Count > 0)
{
foreach(DataRow dr in table.Rows )
{
if(dr.Table.Column.Contain("DateInfo"))
{
// store value in variable
// first approach
}
if(table.Column.Contain("DateInfo"))
{
// store value in variable
// second approach
}
}
}
Which one is best approach?
Will this be enough:
1st Approach: Which will simply check in an entire DataTable.
datatable.Columns.Contains("column")
2nd Approach: which will check for each row collection in DataTable
dr.Table.Columns.Contains("column")
3rd Approach: Which fetch each columns in DataColumnCollection object and then check if it contains the specific field or not.
DataColumnCollection columns = datatable.Columns;
if (columns.Contains(columnName))
So these all approaches are better in their own way. you can use whatever you find it better.
This is best one
dr.Table.Column.Contain("DateInfo")
foreach loop get single row at a time sometimes if any conditional is possible in this method

Get list of post by specific position in query

I need create a loop with specifics post but I would like do it by position (not by id) of all of them. I want to use a single loop with specific position.
Example: (2, 5, 9, etc)
I tried to use wp_query methods but my php knowledge is little.
Outside the loop, create a counter variable:
$post_number = 1;
Then, while you're in the loop, you can check on the contents of the variable to see which post you are at. For instance, in the following example, only the first and second posts will be shown.
Just before you end the loop, add to the counter using $post_number++.
// Start loop
if ($post_number == 1 || $post_number == 2){
// standard loop contents ( the_title(), the_content(), etc)
}
$post_number++;
// stop loop
Why you not try inside a loop for an example:
if ($idpost == "4")
{
// print...
}

CouchDB View with 2 Keys

I am looking for a general solution to a problem with couchdb views.
For example, have a view result like this:
{"total_rows":4,"offset":0,"rows":[
{"id":"1","key":["imported","1"],"value":null},
{"id":"2","key":["imported","2"],"value":null},
{"id":"3","key":["imported","3"],"value":null},
{"id":"4","key":["mapped","4"],"value":null},
{"id":"5,"key":["mapped","5"],"value":null}
]
1) If I want to select only "imported" documents I would use this:
view?startkey=["imported"]&endkey=["imported",{}]
2) If I want to select all imported documents with an higher id then 2:
view?startkey=["imported",2]&endkey=["imported",{}]
3) If I want to select all imported documents with an id between 2 and 4:
view?startkey=["imported",2]&endkey=["imported",4]
My Questtion is: How can I select all Rows with an id between 2 and 4?
You can try to extend the solution above, but prepend keys with a kind of "emit index" flag like this:
map: function (doc) {
emit ([0, doc.number, doc.category]); // direct order
emit ([1, doc.category, doc.number]); // reverse order
}
so you will be able to request them with
view?startkey=[0, 2]&endkey=[0, 4, {}]
or
view?startkey=[1, 'imported', 2]&endkey=[1, 'imported', 4]
But 2 different views will be better anyway.
I ran into the same problem a little while ago so I'll explain my solution. Inside of any map function you can have multiple emit() calls. A map function in your case might look like:
function(doc) {
emit([doc.number, doc.category], null);
emit([doc.category, doc.number], null);
}
You can also use ?include_docs=true to get the documents back from any of your queries. Then your query to get back rows 2 to 4 would be
view?startkey=[2]&endkey=[4,{}]
You can view the rules for sorting at CouchDB View Collation

Flex mobile - How do I move to the next data in List.selectedItem when moving to next page?

When I move page01 to page02, I pass the same data along with it using the following code:
navigator.pushView(Page02, data);
How do I move to page02 with passing the next row of data (instead of the same data)?
In other word, how to increment to the next row of data with pushView?
Thanks.
If you have access to the List component which displays the data you want to pass into views, you can do something like this:
myList.dataProvider[myList.selectedIndex+1]
You'll want to do some checking to make sure that you're trying to reference an index that actually exists:
var mySelectedObject :Object;
if(myList.selectedIndex+1 < myList.dataProvider.length){
mySelectedObject = myList.dataProvider[myList.selectedIndex+1]
} else {
// do some other behaviour; such as selecting the first one in the list
mySelectedObject = myList.dataProvider[0]
}
navigator.pushView(page02, mySelectedObject );

Resources