...
Query to execute.
Example
Basic Query
Code Block |
---|
|
var myTable = $Database.Get({
Parameters : {
TargetSchema : 'HR',
TargetTable : 'Groups'
},
Where : {
Criteria : [
{
Name : 'Name',
Value : 'Administrators'
}
]
},
Order : [
{Name : 'Order', Type : 'Ascending'}
]
}); |
Example
In the example below we queried the Makers table. The result is ordered in descending order and there is only one row because we set the Start parameter to 0 and MaxLength to 1.
Code Block |
---|
|
var myTable = $Database.Get({
Parameters : {
TargetSchema : 'HR',
TargetTable : 'Groups'
},
Columns : [
{Name : 'Order'}
],
Start : 0,
MaxLength : 1,
Where : {
Criteria : [
{Name : 'Name', Value : 'Administrators', Comparison : 'Different'}
]
},
Order : [
{Name : 'Name', Type : 'Descending'}
]
}); |
Example
For example if you need a more complex query, containing multiple AND/OR conditions like "(X OR Y OR Z) AND W", you can use Blocks option. Check the code sample below.
Code Block |
---|
|
var myTable = $Database.Get({
Parameters : {
TargetSchema : 'HR',
TargetTable : 'UserLogons'
},
Where : {
Blocks : [{
Condition : 'And',
Criteria : [{
Name : 'User.EMailAddress',
Value : '...',
Condition : 'Or'
}, {
Name : 'User.EMailAddress',
Value : '...',
Condition : 'Or'
}, {
Name : 'User.EMailAddress',
Value : '...'
},]
}],
Criteria : [{
Name : 'User.Disabled',
Value : 'true',
Condition : 'And',
Comparison : 'Different'
}]
}
}); |
Example
In the query below days gained by an employee is selected with the sum function.
Code Block |
---|
|
var daysGained = $Database.Get({
Parameters : {
TargetSchema : 'HR',
TargetTable : 'LeaveAllowance'
},
Columns : [{
Name : 'DaysGained',
Expression : "Sum(DaysGained)"
}],
Start : 0,
MaxLength : 1,
Where : {
Criteria : [{
Name : 'Employee',
Value : $Initiator.Id
}]
}
});
$Xml.SetValue('GeneralInfo/EarnedDays', daysGained.Rows()[0]["DaysGained"]);
// OR
totalLeaves.Each(function () {
$Xml.SetValue('GeneralInfo/EarnedDays', this.DaysGained);
}); |
Example
...
Code Block |
---|
|
var offerCountByDayTable = $Database.Get({
Parameters : {
TargetSchema : 'OFR',
TargetTable : 'Offers'
},
Columns : [{
Name : "Day",
Expression : "DateTrunc('Day', OfferDate)"
},
{
Name : "Amount",
Expression : "Count(DateTrunc('Day', OfferDate))"
}],
Order : [
{Name : "DateTrunc('Day',OfferDate)", Type : 'Ascending'}
]
});
offerCountByDayTable.Each(function () {
console. Info |
(this.Amount + ' offers made on the date ' + this.Day.toISOString());
});
Examples
...
Code Block |
---|
language | js |
---|
var myTable = $Database.Get({
Parameters : {
TargetSchema : 'HR',
TargetTable : 'Groups'
},
Where : {
Criteria : [
{
Name : 'Name',
Value : 'Administrators'
}
]
},
Order : [
{Name : 'Order', Type : 'Ascending'}
]
}); |
In the example below |
...
Code Block |
---|
|
var myTable = $Database.Get({
Parameters : {
TargetSchema : 'HR',
TargetTable : 'Groups'
},
Columns : [
{Name : 'Order'}
],
Start : 0,
MaxLength : 1,
Where : {
Criteria : [
{Name : 'Name', Value : 'Administrators', Comparison : 'Different'}
]
},
Order : [
{Name : 'Name', Type : 'Descending'}
]
}); |
...
Code Block |
---|
|
var myTable = $Database.Get({
Parameters : {
TargetSchema : 'HR',
TargetTable : 'UserLogons'
},
Where : {
Blocks : [{
Condition : 'And',
Criteria : [{
Name : 'User.EMailAddress',
Value : '...',
Condition : 'Or'
}, {
Name : 'User.EMailAddress',
Value : '...',
Condition : 'Or'
}, {
Name : 'User.EMailAddress',
Value : '...'
},]
}],
Criteria : [{
Name : 'User.Disabled',
Value : 'true',
Condition : 'And',
Comparison : 'Different'
}]
}
}); |
...
Code Block |
---|
|
var daysGained = $Database.Get({
Parameters : {
TargetSchema : 'HR',
TargetTable : 'LeaveAllowance'
},
Columns : [{
Name : 'DaysGained',
Expression : "Sum(DaysGained)"
}],
Start : 0,
MaxLength : 1,
Where : {
Criteria : [{
Name : 'Employee',
Value : $Initiator.Id
}]
}
});
$Xml.SetValue('GeneralInfo/EarnedDays', daysGained.Rows()[0]["DaysGained"]);
// OR
totalLeaves.Each(function () {
$Xml.SetValue('GeneralInfo/EarnedDays', this.DaysGained);
}); |
, offers by suppliers are grouped by the day they made with their count. |
Example
Query with Expression - Advanced
Code Block |
---|
|
var offerCountByDayTable = $Database.Get({
Parameters : {
TargetSchema : 'OFR',
TargetTable : 'Offers'
},
Columns : [{
Name : "Day",
Expression : "DateTrunc('Day', OfferDate)"
},
{
Name : "Amount",
Expression : "Count(DateTrunc('Day', OfferDate))"
}],
Order : [
{Name : "DateTrunc('Day',OfferDate)", Type : 'Ascending'}
]
});
offerCountByDayTable.Each(function () {
console.info(this.Amount + ' offers made on the date ' + this.Day.toISOString());
}); |
See Also