Goal: I'd like to pass a date range into a JQL query in my Platform app.
Issue: JQL request fails
Attempt 1
var dateRange = {
from_date: moment().subtract(30, 'days').format('YYYY-MM-DD'),
to_date: moment(),
};
console.log('dates', dateRange); // logs obj with properly formatted dates
MP.api.jql(function main() {
return join(Events(dateRange), People(), {
type: "inner",
selectors: [{
event: 'Signed In',
selector: 'properties["sampleProp"] > 0'
}]
})
})
JQL Error: moment() is not defined
Attempt 2:
var dateRange = {
from_date: '2019-09-01',
to_date: '2019-09-15',
};
MP.api.jql(function main() {
return join(Events(dateRange), People(), {
type: "inner",
selectors: [{
event: 'Signed In',
selector: 'properties["sampleProp"] > 0'
}]
})
})
JQL Error: dateRange is not defined
How can I pass a date range into MP.api.jql()?
Best answer by evanmoss
Hi mpcomm1,
You need to pass your obj as the 2nd parameter of the mp.api.jql function, like so:
mp.api.jql(yourScript, dateRange).done(function(results) {console.log(results);});
In the query itself, you can access the dateRange as the variable params.
In your example, the code should be something like:
var dateRange = {
from_date: '2019-09-01',
to_date: '2019-09-15',
};
MP.api.jql(
function main() {
return join(Events(params), People(), {
type: "inner",
selectors: [{
event: 'Signed In',
selector: 'properties["sampleProp"] > 0'
}]
})
},
dateRange).done(
function(results) {console.log(results);}
);