Search code examples
dotnetnuke2sxc

How do I get access to current edited entity data like id and guid in modal window of 2sxc DNN module?


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?


Solution

  • 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