0

I'm writing my custom property type for module 2sxc. I mean I'd added a js file inside my app at path "/system/field-string-my-custom-field/index.js" and I'm writing my code there.

And I need to get id (or guid) and entity type of a current edited/created entity in modal window. I didn't find neither id, nor guid of that entity. The only place I've noticed in the html inside iframe that could tell type of entity is title on top of modal window, but that's also not good to take it from there, since it's actually a label, not the name of the entity, which might be different from the actual entity name. When I checked the code that is executed on submit button click - it has object formBuilderRef, which contains all the listed data I need (current entity's id, guid, type). But I didn't succeed in accessing it from my code for now.

Additional info: I'm creating a custom property like this one. So on editing entity with my custom property type there's this modal window. Modal image is from internet but it should be enough to get an idea.

iframe's src property contains EntityId, but it looks like a bad place to take id from, since it contains an id of the entity used to open modal window of 2sxc module, but I could go to app settings and start editing totally different entity that is not on a current page at all. So I need an id of that currently edited entity and correct type, not a label.

So how do I get the data I need from there?

  • I am not sure I understand what you are trying to do. Could you explain further, include some code, or maybe a screenshot so we have more conext? – Jeremy Farrance Jun 30 '22 at 13:58
  • @JeremyFarrance, I've updated a question. If you still need something to be clarified, please let me know. – Constantine Ketskalo Jun 30 '22 at 14:20
  • My bad, read it the first time not realizing you were talking about a custom input type. This is outside my wheelhouse, hopefully someone from 2sxc will catch up to this one soon. – Jeremy Farrance Jul 01 '22 at 16:39

1 Answers1

1

You can get them on

context.target.entity.id and context.target.entity.guid

see also: https://docs.2sxc.org/js-code/edit-form/formulas/context.html

while developing formulas, it's best to also watch the console, because on test-runs it will output all relevant objects data and context to the console.

enter image description here

iJungleBoy
  • 5,325
  • 1
  • 9
  • 21
  • It's not what I was asking. Formulas don't provide enough of functionality for what I'm trying to do. I need one property on edit to request api on backend, then return response and update second property with that response. I have this code already, but I need to get id, guid and type of entity. Where can I find those data properly? – Constantine Ketskalo Jul 07 '22 at 14:55
  • Update: since I've been using `_experimental` property to get target entity guid and it might stop working after a while it was decided to do that via formulas and do it a bit differently. I don't need second property any more. Thanks for a tip. – Constantine Ketskalo Jul 07 '22 at 16:36
  • Do I have access to the entity type from within formulas? I didn't find it so far neither in data, nor in context. There's only type of formula itself. – Constantine Ketskalo Jul 07 '22 at 16:41