From 7c07e2f8530ebabd6c16899be3d8a3ecede4f5bd Mon Sep 17 00:00:00 2001 From: dblythy Date: Wed, 28 Jun 2023 12:36:56 +1000 Subject: [PATCH 1/2] feat: add selectedField to script editor --- src/components/BrowserCell/BrowserCell.react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { From b4783341433d5310b51cc4568446aea6e68ecae9 Mon Sep 17 00:00:00 2001 From: dblythy Date: Wed, 28 Jun 2023 15:59:28 +1000 Subject: [PATCH 2/2] Update README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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: