Hi all,
Outbound transitions are executed as soon as an assessment is done using one of the forms on the application. Is there any way of triggering the outbound on already sent forms / reports?
In order to have older sent data forwarded as well ?
Hi all,
Outbound transitions are executed as soon as an assessment is done using one of the forms on the application. Is there any way of triggering the outbound on already sent forms / reports?
In order to have older sent data forwarded as well ?
You would have to bump up the revision of the saved documents. Loading and saving the documents of interest would be enough to do that. Given outbound processes docs based on the changes feed, these updated docs will now be available for processing.
What does bumping up the revision of saved documents mean
Increasing the revision number of a saved document. This happens every time the document is saved.
And that would have to be individually one by one? Couldn’t be done as a batch right?
You can do it in batch. Query CouchDB for the documents you need and re-save them to increase the revision number.
Hello @derick
Please expound on how “bumping up the revision” can be achieved.
I have more than 300 already saved records that I need to push.
Thanks,
Job
Assuming you wanted to affect all saved reports, you would write a script similar to this. We’ll be querying an existing view to get this data. Depending on what you need you can explore the out-of-the-box views by navigating to https://host/_utils, and select your database of interest (usually, this is medic
). You can find the prebuilt views under the existing design documents
const PouchDB = require('pouchdb-core');
PouchDB.plugin(require('pouchdb-adapter-http'));
PouchDB.plugin(require('pouchdb-mapreduce'));
const DB = new PouchDB('http://<user>:<password>@host/<database-name-usually-medic>');
(async () => {
try {
const result = await DB.query('medic-client/reports_by_form',
{
reduce: false,
include_docs: true
});
for (const blob of result.rows) {
await DB.put(blob.doc);
const doc = await DB.get(blob.doc._id);
// show that the revision increased by 1 after saving the document
console.log(blob.doc._id, blob.doc._rev, doc._rev);
}
} catch (e) {
console.log(e);
}
})();
If you wanted to filter by a particular form, you can add a key argument to the query options.
As an example
const result = await DB.query('medic-client/reports_by_form',
{
reduce: false,
include_docs: true,
limit: 1,
key: ['my_form_name']
});
Let me know if this helps @magp18 @Job_Isabai
@magp18 @Job_Isabai are you still facing challenges with this?
@derick we are yet to implement this. I think we will work on it next week.
Hi Derick,
Thanks a lot for proposing a solution. I am trying it right now, I am running it as a standalone script with nodejs (I presume that is how you intended it) but I keep getting this error
I added this to test on one
if (blob.doc._id == 'known_id'){ await DB.put(blob.doc); }
but didn’t work without it either (exactly as you sent above)
Apologies for the delayed response.
The error indicates that your server is returning a non-JSON response. I’m editing the original example for clarity. Adding /medic
after the host will make your request land on couchdb and the script would run as expected.
Yes this works, thanks!