Using a table display method in a query or view - axapta

I'm trying to make a query against the table HcmWorker and related.
But i want to figure out how to get the result of the display method HcmWorker.primaryDepartmentName() into it's own field in my query.
I also tried creating a view to execute the function via a ViewMethod but that doesn't seem to work as ViewMethods only inject code into the final query against the view.
I'm NOT making a form. The end result has to come through the QueryService.

Sorry, but what you are trying to do is not possible.
You could calculate a non stored field in the postLoad method, but that would impact every access to your table, and it would most likely not work in the context of a query service.

Related

Manually set the current item in a form

What is the code to manually switch a form to a specific record? I was trying to use relations but I can't make a relation to a calculated table, which is where this is coming from, so I have to hardcode which data is populated.
I'm looking for something like
onLoad()
(read the ID from page properties, which I use for globals)
widget.item.select(id);
I think you would want to use:
widget.datasource.selectKey(id);
This works on the assumption that your record is currently loaded in your client however. If your record is not loaded then this will not work.

Filters in AppMaker

I have created one datasource which contains only the rows that fulfil one condition. I want to create some filters in this table... but is not working.
This is the datasource:
For example, I have a text area which filters by the field "Title". Only should appears the row 5 , but the numer 6 it's still here...
This is the event handler code:
Important: in the beginning, I used this filters and they worked properly. They stopped working when i created the filter in the datasource (The one of the first image)
The filter that you are setting via the binding is getting lost when you perform your query script. Essentially, you are creating a query via the binding, then your script is creating a new query that doesn't have the filters you set previously.
Server Script - queryRecords(query: Query)
You'll notice that your query script has access to a parameter query that you can use instead of calling newQuery(). This will have the filter you set via your binding. Additionally, query.run() returns a list of records, so there's no need to iterate over them. Here is all the code you need in your query script:
query.filters.Status._in = ["Published"];
return query.run();

Why is datasource handling in query different from handling it in a form?

I am trying to rewrite some form to the lisp page template. In a list page you must use query as a datasource. I have datasource structure in previous (without list page template) and a new one with list page template. But I am now facing a fact that handling datasource in form is different than handling it in a query.
Can someone explayin why it is done this way and how to make a query so there will be almost no difference between datasource before and after using list page template?
For example I have DSs Object, Sub-Object1, Sub-Object2.
Sub-Object1 have a jointSource Object in properties with exist joint and Sub-Object1 have jointSource Object with Inner Join.
Is there some way to set this in Query DS properties or I must add
datasource to datasource and link in more manually.
Well mayby because a form need more information than query?
If you do have a query already.you can drag it to your form as a datasource.
See http://msdn.microsoft.com/en-us/library/gg844014.aspx
The same effect as a datasource with join type in properties can be done on query by using related datasources. So on the query the structure will be more readable than structure on normal form datasources.

Linq update problem

I have an application with user and admin sections. If an admin updates data with the help of sql datasource then it's updated the database. However, when we retrieve data with linq query then it's showing its old value rather than the updated value.
After some time, the linq query automatically shows the correct value.
I think its caching the value, but I find myself helpless. Please help me with this.
When you say
when we retrieve data with linq query
Do you mean you call your select methods again or are you using the current in memory objects?
In either case, you can always refresh an entity with :
Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, entity)
Make sure that you're using your DataContext efficiently (ideally one per unit of work).
After each update, make sure you call DataContext.SubmitChanges(); to commit your changes back to the database.
Also be aware that any context you instanciate between your changes being added to another context and calling SubmitChanges() will not reflect those changes.

ASP.Net Entity Framework Model

Is it possible to add properties to my model that dont exist in the database?
For example I have a calendar table, I want to retireve this data in my MVC controller then work out time left until each entry starts and return this to the view. So I would like another property in my calendar model to hold time left which is a value that I will generate outside of the database.
I've tried just adding the property but when I do that I get errors because the property is not mapped to anything.
Is this even possible?
Thanks
You should be able to add the property to the Model but you will not be able to query it with LINQ. LINQ will ultimately build and expression which it will want to run against the database using SQL. Its at that point that your LINQ will fail to find a mapping from your property to a field somewhere.
If your query returns an IEnumerable of the actual type on which you have created the property your view may be able to access it. I can't remember if EF insists on mapping in that case, it may do.
You might find that you can create subsequent LINQ query that uses LINQ-to-objects if you want to provide some other composite type to your view.
It's a non-persistent property or transient. I don't know Entity Framwork well but with a quick google search you should find the answer.
BTW you can find a lot of tips here :
http://weblogs.asp.net/zeeshanhirani/archive/2008/12/18/my-christmas-present-to-the-entity-framework-community.aspx
After making a quick search myself and a test in VS2008 I don't see a way to exclude a property from the mapping. Maybe it requires you to edit manually the mapping file ? :(

Resources