diff --git a/README.md b/README.md index e39438399a..14b50243af 100644 --- a/README.md +++ b/README.md @@ -393,6 +393,20 @@ Parse.Cloud.define('deleteAccount', async (req) => { }); ``` +The field which the script was invoked on can be accessed by `selectedField`: + +```js +Parse.Cloud.define('deleteAccount', async (req) => { + if (req.params.selectedField !== 'objectId') { + throw new Parse.Error(Parse.Error.SCRIPT_FAILED, 'Deleting accounts is only available on the objectId field.'); + } + req.params.object.set('deleted', true); + await req.params.object.save(null, {useMasterKey: true}); +}, { + requireMaster: true +}); +``` + ⚠️ 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. For older versions of Parse Server: diff --git a/src/components/BrowserCell/BrowserCell.react.js b/src/components/BrowserCell/BrowserCell.react.js index 11fb0401f8..ddb8650917 100644 --- a/src/components/BrowserCell/BrowserCell.react.js +++ b/src/components/BrowserCell/BrowserCell.react.js @@ -288,7 +288,7 @@ export default class BrowserCell extends Component { callback: async () => { try { const object = Parse.Object.extend(this.props.className).createWithoutData(this.props.objectId); - const response = await Parse.Cloud.run(script.cloudCodeFunction, {object: object.toPointer()}, {useMasterKey: true}); + const response = await Parse.Cloud.run(script.cloudCodeFunction, {object: object.toPointer(), selectedField: this.props.field}, {useMasterKey: true}); this.props.showNote(response || `${script.title} ran with object ${object.id}}`); this.props.onRefresh(); } catch (e) {