Cursor moves to top when refreshing list page grid - axapta

Fellow developers,
I have a custom list page, where a user can select few records, hit a button in Action pane that runs some logic in a class, and all that works fine. My problem is that the cursor does not stay at the same record but goes to the top of the grid. Sounds like a familiar issue?
I store the FormDataSource of the list page using args in the custom class that has all the logic.
I tried few things but none worked.
formDataSource.research(true)
True parameter is supposed to retain the position after research does its job. I am guessing this should have been the most straightforward solution. List page query has 2 datasources joined using Outer join and my guess is research(true) works only with Inner joins.
formDatasource.setPosition(position)
int position;
position = formDatasource.getPosition();
formDatasource.research();
formDatasource.setPosition(position);
I store the position using getPosition and set it again using setPosition. No use.
formDataSource.findRecord()
currentRecord = formDatasource.cursor();
recId = currentRecord.RecId;
formDatasource.reread();
formDatasource.research();
formDatasource.findRecord(currentRecord);
i use the ds.cursor() to get the current record and pass it to findRecord() after research(). No use.
formDataSource.findValue()
currentRecord = formDatasource.cursor();
recId = currentRecord.RecId;
formDatasource.reread();
formDatasource.research();
formDatasource.findValue(fieldNum(Table, RecId), int642str(recId));
i use the ds.cursor() to get the current record and recId and pass it to findValue() after research(). No use.
I debugged the above code and the cursor() method does get the current record and its recId.
I have started to believe that it might be a limitation of list page, and praying that somebody proves me wrong.
Any help is appreciated.

Use Method 3 but like this.
YourTable tmpTable;
currentRecord = formDatasource.cursor();
recId = currentRecord.RecId;
tmpTable = TmpTable::findByRecId(recId);
formDatasource.reread();
formDatasource.research();
formDatasource.findRecord(tmpTable);
Hope this helps.

Try to pass "true" as a parameter for the research method.
salesLine_ds.research(true) works in my case, i.e. if I research the line, cursor stays on the same line.

use the second method like this
int position;
position = formDatasource.getPosition();
//Make your update operations here
formDatasource.research(true);
formDatasource.setPosition(position);
It works for me.

Related

What is the best way to hide "Completed or Cancelled Items" in a table?

So I have setup a model/table that users will use as a project task list. I would like it so that when they change the Status (a field in the model) of an item to either Completed or Cancelled it is hidden.
That way they are only dealing with active entries. But I would also like them to be able to view these hidden (archived) items if needed.
I added the following code to the onAttach option of the table
var datasource = app.datasources.Projects;
datasource.query.filters.Status._notContains = 'Completed';
datasource.load();
And then I have a button with the following code so they can see hidden/archived items:
widget.datasource.query.clearFilters();
widget.datasource.load();
app.closeDialog();
var datasource = app.datasources.Projects;
datasource.query.filters.Status._contains = 'Completed';
datasource.load();
It works, but I feel like there might be a better/more elegant way to accomplish this. Especially since it looks like the app has to load then data, THEN filter it (which results in a slower load). (I think I might have some redundant code in there as well)
Also I feel like I am missing something with my syntax, because I can't get it to filter out Completed AND Cancelled.
Thank you for your help!
If you have a single page of items in the table and there aren't many items, then you can filter on the client side. For example, you can use a binding expression to add a "projectHidden" style to the row based on some logic and then use CSS to change the visibility of the row.
For your second code block, there is no reason to clear filters, load, set the filters and then load again. Just clear the filters, set the new filter, and call load. Also if you are manually controlling the query load, then you might want to uncheck the setting in the data source to automatically load data.
var datasource = app.datasources.Projects;
datasource.query.filters.Status._notEquals = 'Completed';
datasource.query.filters.Status._notEquals = 'Cancelled';
datasource.load();

How can I get the first visible item/index from a ListView?

How can I get the first Item/index that is visible in a ListView? I looked inside the documentation and also searched a lot on the Internet but couldn't find anything. Does anyone know how to do that?
Thank you!
You should use something like that:
ListView {
id: contacts
model: UsersModel
onContentYChanged: {
var CurrentIndexAtTop = indexAt(1, contentY)
var CurrentPropFromModel = UsersModel.get(CurrentIndexAtTop).Name
}
}
if indexAt return -1 means not found, check this if need!
contentY - it is a property of ListView, that return current position top Y-coord of ViewList window on flickable grid ListView.
see documentation for more details http://doc.qt.io/qt-5/qml-qtquick-listview.html#indexAt-method
I know this is late but for others seeking help:
You can use the member method myView.indexAt(QPoint(0,0)) to find the first index.
I've also made a snippet to find all visible indexes in a view if you need that too:
https://gist.github.com/iSplasher/8ebc42eaf9ea206b19bd
Store the selected index when it changes.
Once the model changes and the index becomes -1, you can use positionViewAtIndex to restore the right position.
Here the documentation of the method.
Otherwise, you can do the same relying on the add and remove method.
Obviously, it works as far as the index of the selected item changes.
You can also get the index of the visible item by means of the indexAt method, but I've never used it before, even though it looks easy to use.
So, you have several methods to get the index of the visible item and you can reset the view by means of the method above mentioned.
Based on iSplasher's answer, the following works when QListView has spacing and/or has scroll by pixel:
sp = view.spacing()
first = max(view.indexAt(QPoint(sp, 0)), view.indexAt(QPoint(sp, sp * 2)))

update value only when changed

I had a good look around but couldn't quite find the answer to this one:
I got a Stored Procedure that updates around 30 Fields on a SQL SERVER 2008 Table. It's important for me that one of those Fields is only getting updated, if the value actually changed.
The Stored Procedure Snippet at the moment:
ALTER PROCEDURE test
#p_RoomNo int,
[RoomNo] = #p_RoomNo,
I tried changing it for that particular Column to COALESCE / ISNULL in the SET-Clause of the Procedure, but it still Updates that Column as well
[RoomNo] = COALESCE(#p_RoomNo,RoomNo),
[RoomNo] = ISNULL(#p_RoomNo,RoomNo),
both give me the same Output ...
Do you have any ideas how to NOT Update the Value on Server Side or do I have to put this on a .asp-Forum to change the Application to not pass on any values that are unchanged?
Thanks for any input!
I think the most proper place to check whether the values changed prior to storing the new value is in the asp side of the solution, not in the database. And then you can pass a parameter to the stored procedure.
In the procedure, base on that parameter, you decide whether you should change the value or not.
Edit: Suppose you have a server control of the HiddenField type.
Page_Load(object sender, EventArgs e) {
if (IsPostBack) {
if (myTextBoxIWannaCheckForChanges.Text != myHiddenField.Value) {
// The value has changed.
}
}
}
Note that this will check for changes during the page load. You could also use that kind of logic while handling a button click (if you do so, you don't have to check for a PostBack). Like this:
foo_clicked (object sender, EventArgs args) {
SqlCommand command = // ...snip
// ... set everything you need for your command.
bool changed = (myTextBoxIWannaCheckForChanges.Text != myHiddenField.Value);
command.Parameters.AddWithValue("#changed", changed);
// ... finally let the command execute.
}
Thanks for all replies ...
Changing the Front-End-Application was no option in the end, because changes wouldn't reflect in Future Versions seeing that it's 3rd Party.
I tried most options to alter the SProc but either ran into not getting the desired Field Value updated at all (even when the Value changed) or updating all the times. I decided to look more into the problem from the other side (why I wanted this field not to be updated when the Value didn't change, which was an Update-Trigger, that should only fire when the Value of that Field actually changed.
In the end, the solution was very simple:
Seeing that the
IF UPDATE (RoomNo)
in the Trigger doesn't really compare the Value of the Field but merely if there's an Update called, I simply had to add the comparison via INSERTED and DELETED, so I added the join with DELETED, set my Where Clause on it and it works :)
ALTER trigger [dbo].[UpdateDepartDate]
on [dbo].[Customer]
for update
As
Begin
if update (RoomNo)
Begin
UPDATE Customer
SET [DepartDate] = null
FROM Rooms r
INNER JOIN Customer cu
ON cu.[RoomNo] = r.[Room_ID]
Join INSERTED INS
ON cu.[CU_ID] = INS.[CU_ID]
join Deleted Del
ON INS.[CU_ID] = DEL.[CU_ID]
WHERE INS.[RoomNo] <> DEL.[RoomNo]
END
END
Thought I post it here for anyone interested :)
Thanks again everyone for your help

objective-c if-else statement

I have both a UITextLabel and a UITextView occupying the same real estate, point-for-point in my view. I have an NSMutableArray allocated to populate the UITextLabel based on what the user taps in a table. I would also like to program the app to use the UITextView if and only if the user taps on one specific row. I think this can be accomplished with an if-else (if) statement, but I'm not sure. If that will work, I don't know what to put in the if part. So far, I have this:
if (qux == ??) {
fooTextView.text = textString;
} else {
fooTextLabel.text = textString;
}
I don't know what to set the if statement to. I tried to set it to
if (qux == the really long code containing the single array statement
I want displayed as a UITextView)
but that returned an error. Does anyone have a suggestion on how to get Xcode to recognize my single NSMutableArray table cell with the UITextView and not (also) with the UILabel? As of right now, the app builds but displays the text both in the UITextView, so it scrolls and does exactly what I want but also displays in the UILabel and is static and visible "underneath" the scrolling UITextView.
Also, I'm using an NSMutable Array with initWithObjectAndKeys. In this special case that is the only one of its kind in my UITableView, I use a special key that is only used by this particular part of the array. Is it possible to set it up so it's something regarding:
if (qux == *NSMutableArray with the special key*) {
fooTextView.text = textString;
} else {
fooTextLabel.text = textString;
}
And should I be using an if-else if statement or just an if-else statement?
Use the UITableView Delegate method didSelectRowAtIndexPath: you can get you row index from the NSIndexPath (indexPath.row). The you can use an if-then or a switch to determine which of your controls gets the data. Make sure you set your UITableView's delegate property to your file owner so the UITableView will call back to you controller.
HTH

How do you access a dynamically built select box's selected value with jQuery?

Is there a way to get the selected value (or text, or index) of a select box that the server fills (using ASP.NET) in the client? I've tried $("#ID").val() - but the only time that works is when I continue to another page and then go back. Even then, the value that is returned is the previously selected value - if the user changes the selection, it's not registered unless they leave the page and go back. Go easy on me, I'm new at this...
Update: Tried using a regular html select, same issue (just with a populated entry). Let me elaborate on what I'm trying to do: in a separate page, I'm getting results for an autocomplete search box. The select boxes are for filters. Naturally, if the user selects a filter, I don't want to suggest items that are no longer valid. I'm looking for the keys in the ProcessRequest method of the page that contains autocomplete info.
public override void ProcessRequest(HttpContext context)
{
string respString;
string qsKey = "q";
Customer searchCust = Session[Data.Selected_Customer] as Customer;
Dictionary<string, string> qsDict = context.Request.QueryString.ToDictionary(qsKey);
Shouldn't I get the results (for instance '&ID=foo' on the last line # context.Request.QueryString?
If you want the actual selected item itself:
$("#ID option:selected");
are you sure that 'ID' is really the id of the select box ? been awhile since i used asp.net but i remember it mucked with identifiers a lot
I use the code (below) to manipulate an ASP.NET generated select box. Within the code I obtain the value of the original select box (item). Also consider using the .text() function.
var setValue = function(item){
//if value isn't already selected, postback
if(input.value != item.text())
if(select.attr('onchange'))
eval(select[0].attributes['onchange'].nodeValue);
//set input box value
$(input).val(item.text());
$(input).removeClass('empty');
//select original ASP.NET select value (hidden)
select.val(item.text());
$(lookup).hide();
//show type if present
$('.selectType').show();
};
Hope this helps.

Resources