Technical¶
Tables and Field Definitions Lime CRM¶
Every scheduled lime type requires three tables to exist
- The schedule
- The parameter set
- The lime type to be created
These examples uses scheduled todos but it works for any lime type.
limetype | property | option key | type | configurable |
---|---|---|---|---|
scheduledtodo | limetype | Yes | ||
scheduledtodo | startdate | date | No | |
scheduledtodo | starttime | time | No | |
scheduledtodo | endtime | time | No | |
scheduledtodo | numberofdays | integer | No | |
scheduledtodo | until | datetime | No | |
scheduledtodo | createdaysbefore | integer | No | |
scheduledtodo | lastcreated | datetime | No | |
scheduledtodo | active | yesno | No | |
scheduledtodo | rrulejson | text (length>=256) | No | |
scheduledtodo | rruledescription | text (length>=256) | No | |
scheduledtodo | scheduledtodoparameterset | hasmany (scheduledtodoparameterset) | Yes | |
scheduledtodo | todo | hasmany (todo) | Yes | |
scheduledtodo | history | hasmany (history) | Yes |
The parameter set can have any number of fields, the only required field is a relation back to the schedule.
limetype | property | option key | type | configurable |
---|---|---|---|---|
scheduledtodoparameterset | scheduledtodo | belongsto (scheduledtodo) | Yes |
And finally the limeobjects that are created must have a relation back to the schedule as well as a field to store an identifier used for duplicate prevention.
limetype | property | option key | type | configurable |
---|---|---|---|---|
todo | limetype | Yes | ||
todo | scheduledtodo | belongsto (scheduledtodo) | Yes | |
todo | scheduledid | string (length>=128) | Yes |
When running each schedule there's an optional feature to create history notes related to the schedule.
For this to work the history limetype must have a relation back to the schedule, a field to store the message, an option field for type and a type key.
limetype | property | option key | type | configurable |
---|---|---|---|---|
history | limetype | Yes | ||
history | type | option | Yes | |
history | type | comment | option key | Yes |
history | note | text | Yes | |
history | scheduledtodo | belongsto (scheduledtodo) | Yes |
Schedule Definition¶
The schedules makes up Recurrence Rules. They are split into several lime properties on the schedule:
startdate
is the recurrence start, it is the first possible day the schedule can generate limeobjects for.until
is the upper-bound limit of the recurrence, the last possible day the schedule can generate limeobjects for.starttime
is the time of day the limeobject will be generated for on each recurrence of the schedule.endtime
is the time of day the limeobject will end for each recurrence of the schedulenumberofdays
is an offset that is used whenstarttime
andendtime
isn't on the same day.createdaysbefore
is an offset to control when the limeobject should be created.rruledescription
is a machine generated description of the schedule's recurrence.rrulejson
is a JSON representation of the parameters that can be passed to thedateutil.rrule.rrule()
constructor in Python. There is however some limitations in the available values as per the specification below:
{
"freq": "YEARLY" | "MONTHLY" | "WEEKLY" | "DAILY",
"interval": number,
"count": number,
"byweekno": number[],
"bysetpos": number[],
"bymonth": number[], // Jan=1, Dec=12
"bymonthday": number[],
"byyearday": number[],
"byweekday": number[] // MO=1, SU=6
}
Tasks¶
The package defines the task run_scheduled_limeobjects
. This task loops over all configured schedule lime types and for each processes each schedule. This task is scheduled to run every hour as the user task@scheduledlimeobject
. Set up this user as described in the installation instructions.
Web Components¶
Schedule Activate And Deactivate Button¶
The lwc-limepkg-scheduled-limeobject-schedule-change-status
component is a simple lime button that activates and deactivates the schedule. When a schedule is deactivated by this component, the Run Now button is hidden and the schedule can not be run. It should be placed on the object card of the scheduled limeobject limetype.
Schedule Editor Button¶
The lwc-limepkg-scheduled-limeobject-schedule-editor-button
component is a simple lime button that opens the Schedule Editor in a new dialog. Since the Schedule Editor requires a large screen estate this button is hidden on small devices. It should be placed on the object card of the scheduled limeobject limetype.
Schedule Editor¶
The lwc-limepkg-scheduled-limeobject-schedule-editor
component is a graphical interface for editing a schedule's recurrence. Its root is a limel-dialog
and only works if passed to the dialogService. Use the Schedule Editor Button to open it.
Schedule Preview¶
The lwc-limepkg-scheduled-limeobject-schedule-preview
component is used to provide a preview of the dates the schedule will generate limeobjects for. It is used from within the Schedule Editor.
Schedule Run Now Button¶
The lwc-limepkg-scheduled-limeobject-schedule-run-now-button
component is a simple lime button that trigger the Run Schedule endpoint. It also automatically activates a schedule, if the schedule is not active. It should be placed on the object card of the scheduled limeobject limetype.
Internal Endpoints¶
The package uses several endpoints. None are to be used by external systems.
Schedule¶
This endpoint is used to read and write all properties that makes up a schedule. These properties should preferably only be written using this endpoint.
/limepkg-scheduled-limeobject/<limetype>/<limeobjectid>/
GET
Response
{
"createdaysbefore": 0,
"endtime": "2021-03-23T10:00:00+01:00",
"numberofdays": 0,
"rrulejson": {
"freq": "DAILY",
"interval": 1
},
"startdate": "2021-03-01T00:00:00+01:00",
"starttime": "2021-03-23T07:00:00+01:00",
"until": "2021-04-30T00:00:00+02:00",
"rruledescription": "varje dag 07:00 till 10:00 från och med 2021-03-01 till och med 2021-04-30"
}
PUT
In addition to saving the property values this endpoint will:
- Validate the rrule
- Generate and save a new schedule description (in the language of the logged in user)
Payload
{
"rrulejson": {
"freq": "DAILY",
"interval": 1
},
"startdate": "2021-03-01",
"starttime": "07:00",
"endtime": "10:00",
"numberofdays": 0,
"createdaysbefore": 0,
"until": "2021-04-30"
}
Properties can be left out of the payload if they shouldn't be changed.
Response
{
"createdaysbefore": 0,
"endtime": "2021-03-31T10:00:00+02:00",
"numberofdays": 0,
"rrulejson": {
"freq": "DAILY",
"interval": 1
},
"startdate": "2021-03-01T00:00:00+01:00",
"starttime": "2021-03-31T07:00:00+02:00",
"until": "2021-04-30T00:00:00+02:00",
"rruledescription": "varje dag 07:00 till 10:00 från och med 2021-03-01 till och med 2021-04-30"
}
Recurring Dates for Schedule¶
Shows the passed or configured schedule's resulting dates and description.
/limepkg-scheduled-limeobject/<limetype>/<limeobjectid>/dates/
GET
Shows the schedule's resulting dates and description.
Response
{
"dates": [
{ "start": "2021-03-01T07:00:00", "end": "2021-03-01T10:00:00" },
{ "start": "2021-03-02T07:00:00", "end": "2021-03-02T10:00:00" },
{ "start": "2021-03-03T07:00:00", "end": "2021-03-03T10:00:00" },
{ "start": "2021-03-04T07:00:00", "end": "2021-03-04T10:00:00" },
{ "start": "2021-03-05T07:00:00", "end": "2021-03-05T10:00:00" },
{ "start": "2021-03-06T07:00:00", "end": "2021-03-06T10:00:00" },
{ "start": "2021-03-07T07:00:00", "end": "2021-03-07T10:00:00" },
{ "start": "2021-03-08T07:00:00", "end": "2021-03-08T10:00:00" },
{ "start": "2021-03-09T07:00:00", "end": "2021-03-09T10:00:00" },
{ "start": "2021-03-10T07:00:00", "end": "2021-03-10T10:00:00" },
{ "start": "2021-03-11T07:00:00", "end": "2021-03-11T10:00:00" },
{ "start": "2021-03-12T07:00:00", "end": "2021-03-12T10:00:00" },
{ "start": "2021-03-13T07:00:00", "end": "2021-03-13T10:00:00" },
{ "start": "2021-03-14T07:00:00", "end": "2021-03-14T10:00:00" },
{ "start": "2021-03-15T07:00:00", "end": "2021-03-15T10:00:00" }
],
"description": "varje dag 07:00 till 10:00 från och med 2021-03-01 till och med 2021-04-30"
}
PUT
Shows the passed schedule's resulting dates and description. If a property is not included in the payload it is taken from the schedule as is in the database. The description will be in the logged in user's language.
Payload
{
"rrulejson": {
"freq": "DAILY",
"interval": 1
},
"startdate": "2021-03-01",
"starttime": "07:00",
"endtime": "10:00",
"numberofdays": 0,
"createdaysbefore": 0,
"until": "2021-04-30"
}
Response
{
"dates": [
{ "start": "2021-03-01T07:00:00", "end": "2021-03-01T10:00:00" },
{ "start": "2021-03-02T07:00:00", "end": "2021-03-02T10:00:00" },
{ "start": "2021-03-03T07:00:00", "end": "2021-03-03T10:00:00" },
{ "start": "2021-03-04T07:00:00", "end": "2021-03-04T10:00:00" },
{ "start": "2021-03-05T07:00:00", "end": "2021-03-05T10:00:00" },
{ "start": "2021-03-06T07:00:00", "end": "2021-03-06T10:00:00" },
{ "start": "2021-03-07T07:00:00", "end": "2021-03-07T10:00:00" },
{ "start": "2021-03-08T07:00:00", "end": "2021-03-08T10:00:00" },
{ "start": "2021-03-09T07:00:00", "end": "2021-03-09T10:00:00" },
{ "start": "2021-03-10T07:00:00", "end": "2021-03-10T10:00:00" },
{ "start": "2021-03-11T07:00:00", "end": "2021-03-11T10:00:00" },
{ "start": "2021-03-12T07:00:00", "end": "2021-03-12T10:00:00" },
{ "start": "2021-03-13T07:00:00", "end": "2021-03-13T10:00:00" },
{ "start": "2021-03-14T07:00:00", "end": "2021-03-14T10:00:00" },
{ "start": "2021-03-15T07:00:00", "end": "2021-03-15T10:00:00" }
],
"description": "varje dag 07:00 till 10:00 från och med 2021-03-01 till och med 2021-04-30"
}
Run Schedule¶
Creates a task that runs the lime object creation for this schedule in the background. Use this when waiting for the next execution of the scheduled task is not an option.
/limepkg-scheduled-limeobject/<limetype>/<limeobjectid>/run/
POST
Payload:
None
Response:
{
// information about the created task
}
Action Pad¶
Schedule Editor¶
The scheduled_limeobject_scheduleeditor
application provides an interface for editing the rrulejson
property on the schedule in a visual way.
It is intended to be opened in a new window, this can easily be done in the action pad like below:
<a
data-bind="vba:'AO_Scheduled_LimeObject.ShowScheduleEditor', text:'Schedule editor', icon: 'fa-calendar'"
></a>
Run Now¶
To add a link to run the schedule immediately as an action in the action pad, copy the following:
<script type="text/javascript">
function runScheduleNow() {
$.support.cors = true;
$.ajax({
url: encodeURI(
lbs.limeDataConnection.Database.FullActiveServerName +
"/" +
lbs.activeDatabase +
"/limepkg-scheduled-limeobject/" +
lbs.activeClass +
"/" +
lbs.activeInspector.Record.ID +
"/run/"
),
headers: {
sessionId: lbs.limeDataConnection.Database.SessionID,
"Content-Type": "application/json",
},
method: "POST",
cache: false,
success: function (data) {
alert("The schedule will run in the background.");
},
error: function (data) {
try {
jason = JSON.parse(data.responseText);
alert(jason.message || jason.error);
} catch {
alert(data.responseText);
}
},
});
}
</script>
<a
onclick="runScheduleNow()"
data-bind="text:'Run schedule now', icon: 'fa-bullseye'"
></a>
VBA Module - AO_Scheduled_LimeObject¶
AO_Scheduled_LimeObject.ShowScheduleEditor
Opens the schedule editor in a new window.
Templating¶
One limeobject is created for each parameters record on a schedule for each recurrence. The combination of schedule and parameters makes up the template for the new limeobject. As per the configuration properties are copied from both to the new limobject.
Almost all property types can be copied, the notable exception is the hasmany
relation.
When copying string
or text
properties additional string substitution takes place. This is triggered by using the $
character followed by a key. For example ${strawberry}
would be replaced by the value of the strawberry
property on either the schedule of parameter when copying it to the new limeobject.
The following substitution keys are available:
- All
string
andtext
properties on the schedule and parameters. - All
belongsto
properties on the schedule and parameters, in this case the descriptive is used. ${month}
is the month, for example january.${week}
is the week number.${day}
is the day, for example monday.
Substitution keys that don't exist are left as is when copying the value.