--Insert new incident or update existing one
INSERT INTO incident (title, description, estimated_duration, who_is_affected, date_time, severity, status )
VALUES (:Title, :Description, :EstimatedDuration, :WhoIsAffected, :DateTime, :Severity, :Status );

INSERT INTO  incident_application (incident_id, application_id) 
SELECT last_insert_rowid(),
        CAST(application.value AS INTEGER)
FROM json_each(:Applications) as application
WHERE application.value IS NOT NULL;

SELECT 'redirect' AS component, 'incidents.sql?id=' || last_insert_rowid() AS link;