Display Distinct values in LightSwitch browse screen - visual-studio-2013

i have one browse screen which is fetching value from one entity(Attached to SQL datasource),
the entity will look like the below snapshot.
So in the browse screen its coming with all row values (1,2,3 and 4) even though i removed the Role field from the screen. I want to display the distinct Emp ID, Name, Age. Please give me some suggestion.

The question tags Lightswitch 2013 and 2012 so it's not clear what the OP is using. Views handling in Lightswitch before VS2013 Update 2 can be a little more challenging (particularly around the definition of key fields) so the other possibility is to use a WCF-RIA service to reshape the data. Having a WCF-RIA service ready to go always comes in handy eventually, even if there are annoying limitations and quirks there as well.
The exact steps depend slightly on what version of VS you are using:
The canonical article by Eric Erhardt - http://blogs.msdn.com/b/lightswitch/archive/2011/04/08/how-do-i-display-a-chart-built-on-aggregated-data-eric-erhardt.aspx
An up to date version for VS2013 - http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/2226/Creating-a-WCF-RIA-Service-for-Visual-Studio-2013.aspx
Happy to help further with specific queries if you decide to go down the WCF-RIA route.
Phil

If you don't have the option of driving your Browse screen from your employee table I'd suggest creating a SQL view similar to the following: -
CREATE VIEW [dbo].[EmployeeView]
AS
SELECT DISTINCT
EmpId,
Name,
Age,
Role
FROM
dbo.YourTable
You can then attach to the view in LightSwitch and base the Browse screen on the attached view.
However, please bear in mind that you will only be able to view and not update the information as this type of view uses the DISTINCT clause.
The following blog post provides some basic details of using views in LightSwitch: -
Attaching to SQL Views

Related

Query a CRM SavedQuery via SQL SSMS

In SSMS I can go to our CRM database and run these:
SELECT *
FROM SavedQueryBase
WHERE [name] LIKE 'customer%';
SELECT *
FROM SavedQuery
WHERE [name] LIKE 'customer%';
Which both return information on the CRM View.
My Question is - is it possible to actually execute the view in SSMS? In CRM I get 4,000+ records in the View and I need to see these same records in SSMS. I can't seem to find out how to do it.
Ok ... found it, but posting it here for the next poor person who also can't figure it out.
You need to look at the FetchXML field which comes back as a result of the queries I posted in the Question.
Then you need to decipher those to build your query. All the info is in the XML, the base table, the fields selected, ordering etc ... Just takes some effort, and of course if the user changes the view, you'll need to redo it.

How to make drop-down menu within Oracle Application Express?

I would really appreciate if anybody could shed some light on this, as search engine results have been singularly unhelpful so far.
I am attempting to build a GUI for an oracle database through Application Express. There tend to be tricks of how to set up drop down menus through the Graphical User Interface of the product that one uses (for instance I would know how to do this in a product like Microsoft Access).
For instance I have this form
The foreign key for Business (FK_BUSINESS_ID) is just an integer - not terribly user friendly! If it could be a drop down list of business names (BUSINESS.NAME), it would be great. Hiding the business primary key (BUSINESS_ID) would make it look nicer, but isn't altogether relevant.
I have found the source controls for the element in question.
What sort of SQL (or even PL/SQL) could be used to both display this data from the other table, and return the selected foreign key selected by the user when the form is sent?
Solution
Open up the item, and change the type to Select List
For List of Values Definition, enter select BUSINESS.NAME, FK_BUSINESS_ID from [TABLE]
Explanation
Select list shows display values to the user and returns the corresponding ID. Your source can remain the same as before.

Very slow search of a simple entity relationship

We use CRM 4.0 at our institution and have no plans to upgrade presently as we've spend the last year and a half customising and extending the CRM to work with our processes.
A tiny part of model is a simply hierarchy, we have a group of learning rooms that has a one-to-many relationship with another entity that describes the courses available for that learning room.
Another entity has a list of all potential and enrolled students who have expressed an interest in whichever course.
That bit's all straightforward and works pretty well and is modelled into 3 custom entities.
Now, we've got an Admin application that reads the rooms and then wants to show the courses for that room, but only where there are enrolled students.
In SQL this is simplified to:
SELECT DISTINCT r.CourseName, r.OtherInformation
FROM Rooms r
INNER JOIN Students S
ON S.CourseId = r.CourseId
WHERE r.RoomId = #RoomId
And this indeed is very close to the eventual SQL that CRM generates.
We use a Crm QueryEntity, a Filter and a LinkEntity to represent this same structure.
The problem now is that the CRM normalizes the a customize entity into a Base Table which has the standard CRM entity data that all share, and then an ExtensionBase Table which has our customisations. To Give a flattened access to this, it creates a view that merges both tables.
This view is what is used by the Generated SQL.
Now the base tables have indices but the view doesn't.
The problem we have is that all we want to do is return Courses where the inner join is satisfied, it's enough to prove there are entries and CRM makes it SELECT DISTINCT, so we only get one item back for Room.
At first this worked perfectly well, but now we have thousands of queries, it takes well over 30 seconds and of course causes a timeout in anything but SMS.
I'm given to believe that we can create and alter indices on tables in CRM and that's not considered to be an unsupported modification; but what about Views ?
I know that if we alter an entity then its views are recreated, which would of course make us redo our indices when this happens.
Is there any way to hint to CRM4.0 that we want a specific index in place ?
Another source recommends that where you get problems like this, then it's best to bring data closer together, but this isn't something I'd feel comfortable in trying to engineer into our solution.
I had considered putting a new entity in that only has RoomId, CourseId and Enrolment Count in to it, but that smacks of being incredibly hacky too; After all, an index would resolve the need to duplicate this data and have some kind of trigger that updates the data after every student operation.
Lastly, whilst I know we're stuck on CRM4 at the moment, is this the kind of thing that we could expect to have resolved in CRM2011 ? It would certainly add more weight to the upgrading this 5 year old product argument.
Since views are "dynamic" (conceptually, their contents are generated on-the-fly from the base tables every time they are used), they typically can't be indexed. However, SQL Server does support something called an "indexed view". You need to create a unique clustered index on the view, and the query analyzer should be able to use it to speed up your join.
Someone asked a similar question here and I see no conclusive answer. The cited concerns from Microsoft are Referential Integrity (a non-issue here) and Upgrade complications. You mention the unsupported option of adding the view and managing it over upgrades and entity changes. That is an option, as unsupported and hackish as it is, it should work.
FetchXml does have aggregation but the query execution plans still uses the views: here is the SQL generated from a simple select count from incident:
'select
top 5000 COUNT(*) as "rowcount"
, MAX("__AggLimitExceededFlag__") as "__AggregateLimitExceeded__" from (select top 50001 case when ROW_NUMBER() over(order by (SELECT 1)) > 50000 then 1 else 0 end as "__AggLimitExceededFlag__" from Incident as "incident0" ...
I dont see a supported solution for your problem.
If you are building an outside admin app and you are hosting CRM 4 on-premise you could go directly to the database for your query bypassing the CRM API. Not supported but would allow you to solve the problem.
I'm going to add this as a potential answer although I don't believe its a sustainable or indeed valid long-term solution.
After analysing the indexes that CRM had defined automatically, I realised that selecting more information in my query would be enough to fulfil the column requirements of an Index and now the query runs in less then a second.

Dynamics AX 2009 Database Diagram

i'm desperately searching for dynamics ax 2009 database diagram.
Does anyone have it ?
Thank you
For a list of tables in AX 2009 see the MSDN documentation Dynamics AX 2009 Tables
To create a Visio UML Data Model diagram, place the tables you want to include in a project and use the Reverse Engineering Tool
With more than 2000 tables it would be a huge diagram.
If you look at the tables in the AOT most of them have relations set on them
You can also use the Cross-Reference
Select the table / table field you are interested in knowing more about.
Right click / Add-Ins / Cross-Reference / Used by
Here you will get a complete list of everywhere the selected object is used
The Cross reference must be updated ofcourse - prior to this.
It can be a long process - most the time it is only updated in Development and Test environments
You do that by clicking the main AOT node. Right click here and do like mentioned above. But select 'Update' instead of 'Used By'. It may take hours
Me too. Let us know if you find anything because I don't think it exists... In the meanwhile try this unfinished AX40datamodel.doc document to kick-start your knowledge.

Surely Salesforce supports regular old grouping and summarization in reports?

So the reporting system in Salesforce is a bit restricting. It seems there is no editor for an xml or other markup language to create reports in; apart from formulas you're stuck in the website drag and drop ui.
There seems to be 3 types of reports in Salesforce Tabular, Summary and Matrix. The first kind is kind of useless for more advanced reports, since it doesn't support forumulas (if both fields are in the same table you can work around this with calculated fields). However with all 3 I've found it difficult to impossible to make a report with basic details and summarized figures.
An example:
I've added a custom field "company size" to the Account table/object. This tracks the approximate number of employees working at the customers company (ever taken one of those surveys that asked you for a range of how many employees worked in your organization). I then have a custom table/object for sales, listing the account, the date and the volume ($).
I would think it would be a simple to create spreadsheet style report with each row listing an account, which state it was based in, how many employees they had, followed by their total sales and sales/employee (a formula of volume/employees).
But the grouping and summarization options don't seem to work that way. Grouping in both the Summary and Matrix report types seems to want to treat each grouped field as a seperate level, so with the 3 fields related to the account I get 3 cascading fields in a stair like arrangement, instead of being able to put them on one row.
It gets worse with the summarization - no matter what I and other colleague have tried the summarization doesn't seem to work. If an account has 50 sales we end up with 50 rows, even if we click the little arrow beside the column, click summarize and check Sum.
From an SQL perspective this report seems like something you would teach students in the first week, yet its really not obvious how translate this into something Salesforce can understand. A lot of the web ui is not discoverable (dragging fields provides no feedback as to why it can't be dropped in a particular place, some options are hidden unless you hover the mouse over the right place) so I would not be surprised if I've missed a crucial step.
So, is there an option to make this work (particularly getting sales to be totaled as a single cell for each account, not 2 or 5 or 50), maybe a distict checkbox lurking behind an innocent blank area?
Given the lack of calculated fields in the report, you need to create the formula at the object level. If it's not useful in the detail page, don't include it in the page layout. It will still be available in reporting.
The summarization/grouping options work as in SQL, but you can only group by one field at a time.
However, the result view in "show details" mode is not like a simple SQL query - more like using windowing functions where the result output can contain both groupings with aggregations at those levels, and the detail rows that fed into that grouping.
In "hide details" mode, the detail rows are not shown, and so only grouping levels and the aggregates are shown.
So, it looks like you can either:
group by state, then account, sum your employees, sum sales, and then a Custom Summary formula of sum:sales/sum:employees
or
create a formula field on account to do sales/employees
tabular report with fields of: account, state, employees, sales, your new field.
Also, if you want an XML editor, you can edit the XML for reports (as with many other parts of salesforce setup) via the metadata API and the force.com plugin for eclipse. But it's mainly for tweaking reports, or version control, or mass-actions, as there is no preview/run operations, it's mostly a metadata management system.

Resources