How do you fetch records or update them from a client script?
I have a list of records; I select a few and hit the custom button. I can see the args.selected array with the selected record IDs, but how should I look up the records and update them from the script?
1 Like
Have a look at this and this (mainly this bit here – that is where the ComposeHelper
class is under)
2 Likes
Hi @tjerman , thanks for the quick answer, however I ran into an issue, I cannot fetch the records from the namespace, I use the ctx.Compose.findRecords() function and I get the following error:
index.es.js:12232 Uncaught (in promise) Error: unexpected input type for module resolver
at Zc.<anonymous> (index.es.js:12232:35)
at Generator.next (<anonymous>)
at index.es.js:270:71
at new Promise (<anonymous>)
at I (index.es.js:266:12)
at Zc.resolveModule (index.es.js:12169:16)
at Zc.<anonymous> (index.es.js:11638:25)
at Generator.next (<anonymous>)
at index.es.js:270:71
at new Promise (<anonymous>)
My trigger is:
triggers (t) {
console.log('t' + JSON.stringify(t, null, 2))
return t.on('manual')
.for('compose')
.where('module', 'claim')
.where('namespace', '<handle/slug of my namespace(nda)>')
.uiProp('app', 'compose')
},
It is being said here that without specifying the module it should use the current one, which is in my case the ‘claim’ module. And the module is defined as you can see here:
What am I doing possibly wrong? Thanks in advance
1 Like
Could you show the entire script/the offending bit?
Yes ofc, here it is:
export default {
label: 'Just a test',
description: 'Testing out automation scripts',
triggers (t) {
console.log('t' + JSON.stringify(t, null, 2))
return t.on('manual')
.for('compose')
.where('module', 'claim')
.where('namespace', '<ns>')
.uiProp('app', 'compose')
},
async exec (args, ctx) {
const records = ctx.Compose.findRecords()
console.log('records:'+ JSON.stringify(records, null, 2))
}
}
1 Like
Hmm; looks fine to me…
What happens if you try to pass in some params? So
ctx.Compose.findRecords({}, 'claim')
You could also try to do it like this:
async exec (args, { Compose }) {
const records = Compose.findRecords()
console.log('records:'+ JSON.stringify(records, null, 2))
}
Ages back, there was some bug regarding params and restructuring.
Give it a shot; probably won’t change anything but hey.