XDS Policy - Pass a method to value property in Datasource of a query - dynamics-ax-2012

I am working on Extensible Data Security(XDS) Policy in Dynamics AX 2012.
I have made an X++ query which returns a warehouse number id depending on the currently logged in worker which is working fine.
In my query I have 1 datasource (InventLocation) table and in the range node I have added InventLocationId field when I hardcode a static value(like W1001) in the value property my program is working fine but when I call my function in the value property it doesn't work.
I have tested my X++ query in the job and it is working like it's used to. The problem which I see is that whenever a worker logins my class's method doesn't execute.
I've been stuck on this problem for a few days now. Would really appreciate any help.

I found the solution from the following document
http://www.microsoft.com/en-us/download/details.aspx?id=26921

Related

Using a table display method in a query or view

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.

Sql Database Server

Hi i have a sql database server runnin on my desktop. I want to create an asp.net application to detect when new data has been inserted into the database. Is there a command in visual studio to detect when theres new data right away?
Use the timestamp datatype on each column. This will stay identical until a change is made to any column in that row. If you combine this with the rowcount you can be certain if anything has changed in your database. You would need to cache the current timestamps and row count and compare them with the results of a query, you can then find out if there is a change.
So in your answer to:
Is there a command in visual studio to
detect when theres new data right
away?
Yes there is, although its not a command is the timestamp function (not to be confused with anything to do with the time)
Perhaps you need to provide more details to your scenario since constant querying of the database might not be the best way forward.
You can get a row count of your dataset and create a application
IN VB
Dim i as Integer
i=dataset.tables("table").rows.count
in sql backed return a count of a table and create a ASP.Net website to get the count and when count change alerts you
It may be heavier duty than you are looking for, but SQL Notification Services will do what you want. Essentially you execute a query and tell notification services you want to be notified whenever re-running that query would produce different results.
if you are using caching you can make it dependent on sql.
or you can fire email using sql trigger so when ever trigger get fired you will receive an email.
otherwise you will have to check your db again and again for any changes.
if you can provide more details about exact situation , we can provide more specific solution
You can create a webservice and call it using javascript.
here you can find sample how to call webservice using javascript:
function CallWebservice()
{
myWebService.isPrimeNumberWebService.callService(isPrimeNumberResult, "IsPrime",
testValue.value);
setTimeout("CallWebservice()",100);//here set time according to your requirement
}
For timer in javascript:
http://dotnetacademy.blogspot.com/2010/09/timer-in-javascript.html
For webservice in javaScript:
http://www.webreference.com/js/tips/020715.html
How to call webservice in JavaScript for FireFox 3.0

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 ? :(

Limiting records returned by a sqldatasource, using session variable in where clause

I have a web application which has a Sql Server database on the backend. As the site will be rolled out to different clients (or different virtual directories in IIS), each client derivative of the site will use the same backend.
There is an admin page where text on the site can be changed (enter text in a listview, and choose the page to select where that text will show up, and also you can see company-specific details in the other listviews. As this is a shared database, that means a client can see each other's data.
What I am trying to do is store the accountId (a guid returned from the database from login_authenticate), and stick this into session. I then retrieve this on the admin page, and I want to use this value (But it's always 0000-0000 etc), to limit the records returned in the listview.
Is there an example of this? Also, how can I set the default value (this is in the where clause of SqlDataSource), to programatically what the account id is (so I can give me all records = what the current accountid is, or perhaps, what the login is - this is stored in the account table).
Thanks
This is what I tried.
What I am confused about, though, is whether the where clause, when using a session object, is getting an object that I have written the code to retrieve from the session, or an object I have only added but not retrieved. I get the accountID when logging in (verified via stepping in - obviously - or the login will fail).
I will try again with storing the object in session # the login page when I have just retrieved the accountid variable, and then retrieve it on another page.
For some reason I keep getting 0s so I will look at this in my application.
It sounds like your method should be working. I would follow a debugging process:
Check that you are getting the accountID value from the database. Print it on screen immediately after retrieving the value for the first time.
If this is working, store the value in the Session and immediately retrieve it, and check that you are getting the value back.
Create 2 test pages, one where you set the Session variable and another where you retrieve it.
I know this seems really basic, but the failure is being introduced somewhere in the above 3 places. If you can find which step fails, you will be able to fix it.

Resources