Skip to content

Commit e98d653

Browse files
authored
feat: Add parameter selectedField to script payload to determine which object field was selected when script was invoked (#2483)
1 parent 8e6f061 commit e98d653

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,20 @@ Parse.Cloud.define('deleteAccount', async (req) => {
393393
});
394394
```
395395

396+
The field which the script was invoked on can be accessed by `selectedField`:
397+
398+
```js
399+
Parse.Cloud.define('deleteAccount', async (req) => {
400+
if (req.params.selectedField !== 'objectId') {
401+
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, 'Deleting accounts is only available on the objectId field.');
402+
}
403+
req.params.object.set('deleted', true);
404+
await req.params.object.save(null, {useMasterKey: true});
405+
}, {
406+
requireMaster: true
407+
});
408+
```
409+
396410
⚠️ Depending on your Parse Server version you may need to set the Parse Server option `encodeParseObjectInCloudFunction` to `true` so that the selected object in the data browser is made available in the Cloud Function as an instance of `Parse.Object`. If the option is not set, is set to `false`, or you are using an older version of Parse Server, the object is made available as a plain JavaScript object and needs to be converted from a JSON object to a `Parse.Object` instance with `req.params.object = Parse.Object.fromJSON(req.params.object);`, before you can call any `Parse.Object` properties and methods on it.
397411

398412
For older versions of Parse Server:

src/components/BrowserCell/BrowserCell.react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export default class BrowserCell extends Component {
288288
callback: async () => {
289289
try {
290290
const object = Parse.Object.extend(this.props.className).createWithoutData(this.props.objectId);
291-
const response = await Parse.Cloud.run(script.cloudCodeFunction, {object: object.toPointer()}, {useMasterKey: true});
291+
const response = await Parse.Cloud.run(script.cloudCodeFunction, {object: object.toPointer(), selectedField: this.props.field}, {useMasterKey: true});
292292
this.props.showNote(response || `${script.title} ran with object ${object.id}}`);
293293
this.props.onRefresh();
294294
} catch (e) {

0 commit comments

Comments
 (0)