The columns
section of the XML document refer to the columsn that will be offered in the Data Export Manager screens. The text of the column name is arbitrary and can be anything, but the <column column="TABLE.FIELD">
portion must refer to a "core" table of powerschool. When in doubt, use column="STUDENTS.ID"
Avoid using DCID of any table in the column parameter as it might render the query disabled in DEM (grayed out). Reason being the DCID of most tables, starting with Students, is a non-editable identifier key even for system admin roles. Having DCID in SQL and in feild access is acceptable.
<columns>
<column column="STUDENTS.ID">Student_Number</column>
<column column="STUDENTS.ID">Enroll_Status</column>
<column column="STUDENTS.ID">Family_Ident</column>
</columns>
The total number of columns returned by the query must match the number and sequence of column
references in the XML document. Inner text (alias) of column attributes does NOT have to match the SQL query aliases as long as each column has a unique alias. Student_Number is equally as acceptable as StudentID, SNUM, DCID, or HELLO.World (with HELLO being displayed as the main table in the DEM). column property values are not case sensitive, neither are aliases in column inner text.
Example:
<queries>
<!--set name here (also applies to permissions_root-->
<query name="com.foo.bar" coreTable="students" flattened="false">
<!--add description here-->
<description>foo example</description>
<!--number of columns here must match number sql returns-->
<columns>
<column column="STUDENTS.ID">StudentName</column>
<column column="STUDENTS.ID">Date</column>
<column column="STUDENTS.ID">Food</column>
</columns>
<!--SQL query in format <![CDATA[QUERY]]>-->
<sql>
<![CDATA[
select
foo.name as "Name"
foo.date as "Date"
foo.food as "Food"
from foobartable as foo
]]>
</sql>
</query>
</queries>
The coreTable=
value must refer to a known PowerSchool core table. This determines which menu the named query appears in on the Data Export Manager screen. When in doubt, use students
. Do not use database extensions. coreTable property name is case-sensitive, it's value is not. "students" is the same as "STUDENTS" or "Students".
Example:
<query name="com.foo.bar" coreTable="students" flattened="false">
Long query names will result in odd errors and an inability to install and run the Named Query. Do keep in mind that PowerSchool Developer guide advises to have a 5-part query name with first two parts as the reversed domain name, third part as department or purpose, fourth part as general area (students, attendance, test, etc), and fifth part being the query name like "ham_anf_eggs". The plugin does accept standard names like "Ham and Eggs" but these names could pose issues when called via API or in page fragments.
Example:
<query name="com.foo.spam_ham_ham_eggs_and_ham" coreTable="students" flattened="false">
Alternative:
<query name="com.foo.spam_ham_2" coreTable="students" flattened="false">
While this is completely valid SQL, PowerQuery can't handle it and direct column references should be used. NB! There is a counter example to this wehre a wildcard must be used when using CTEs. See the errors section below for more information.
Example:
Select *
From table table
When installing the plugin this will result in an error that indicates that the query cannot determine a column name
Alternative:
-- select the first column
Select 1
From table table
When enabling a plugin it will be validated and sometimes kick errors associated with the format of the SQL. Some errors will also manifest when running a plugin from the Data Export Manager screens.
Case 1 - ORDER BY Mismatch
This appears to be due to a column beiing referenced by only the column name in an ORDER BY
clause.
Example:
ORDER BY foobar
Alternative:
ORDER BY spam.foobar
Case 2 - Using CTE Tables
When using CTE joins, you may need to use a SELECT *
rather than a table alias.
Example:
-- CTE use:
LEFT JOIN sca_complete contact1 ON contact1.studentdcid = s.dcid AND contact1.contactprio = 1
LEFT JOIN sca_complete contact2 ON contact2.studentdcid = s.dcid AND contact2.contactprio = 2
WHERE s.enroll_status = 0
ORDER BY s.lastfirst
Alternative:
LEFT JOIN (SELECT * FROM sca_complete) cone ON cone.studentdcid = s.dcid AND cone.contactprio = 1
LEFT JOIN (SELECT * FROM sca_complete) ctwo ON ctwo.studentdcid = s.dcid AND ctwo.contactprio = 2
WHERE s.enroll_status = 0
ORDER BY s.lastfirst
Unable to execute the query operation due to an invalid parameter. Update your filter values and try again.
An unexpected error occurred while communicating with the server. Please contact your administrator
These errors tend to be associated with using order by
statements that are valid SQL, but do not refer to selected columns. To resolve this issue:
- Ensure that all
order by
statements in the SQL query are fields that are directly represented in theselect
section. - Entirely remove the
order by
statements -- in some cases this resolves the above error entirely
Example:
select distinct
'enrollment' as "type",
'UPDATE' as "action",
'T_'||teachers.teachernumber as "child_code",
'Instructor' as "role_name",
teachers.homeschoolid as "parent_code"
from TEACHERS TEACHERS
where teachers.status =1
and length(teachers.email_addr) >0
/*
note that the teacher number is not a directly select'd statement.
In this case it is concat'd to 'T_'
*/
order by teachers.teachernumber asc
Alternative:
select distinct
'enrollment' as "type",
'UPDATE' as "action",
'T_'||teachers.teachernumber as "child_code",
'Instructor' as "role_name",
teachers.homeschoolid as "parent_code"
from TEACHERS TEACHERS
where teachers.status =1
and length(teachers.email_addr) >0
/*
homeschoolid is directly select'd
*/
order by teachers.homeschoolid asc
**NB!** Sometimes these errore can be caused by comparison operations if single quotes are omitted for numeric values. Even though it will return correct results in an SQL editor/engine, the PowerQuery will not work. For example, if using WHERE enroll_status = 0, encase 0 in quotes as '0' to treat it as a string.
Hi. I found your gist repo while troubleshooting an issue with my powerquery. After extensive testing and getting definitive answers on what works and what doesn't, I've made notes and added updates to my gist fork. There are several key points about DCID, naming, and properties that are worth mentioning. Not sure which version of SIS this arrived with, but queries that explicitly callout Students.DCID in the column attribute's column property --- result in a query that's disabled (grayed out) in the DEM listing. Even thought PS Dev claims you have to list the unique ID of the coreTable, it's quite the opposite when it comes to some DCIDs. Inner text of column attributes is also not relevant to the plugin function as long as they conform to correct syntax and are unique within the query name.