getElementName returns null

I produce a lable in a form

// "labelText is a global variable where I can put the name of the label
var form = solutionModel.getForm('contacts_profile')
	var label = form.newLabel(labelText,0,10,80,20)
	label.transparent = true
	label.name = labelText
	var name = label.name
	forms.contacts_profile.controller.recreateUI()

Then I want to retrieve the name of the label in a onDrop method

var name = elem.getElementName()
	var x = elem.getX()
	var y = elem.getY()
	application.output(name)

“name” returns null while x and y have a value.

What do I do wrong?

thanks for any help.

Since you say that labelText is a global, what if you do:

var label = form.newLabel(globals.labelText,0,10,80,20)
label.name = globals.labelText;

Sorry Patrick, my mistake, I mean a form variable.

I made some tests and my conclusion is that getElementName doesn’t work in designeMode.

What I don’t get is that if I call the data (event.data) it returns a name.

[LABEL,[name:aaa,x:126,y:11,width:80,height:20,label:aaa]]

Any suggestion how to get the name of an element in designMode?

What is that elem that you get?
i guess that is the runtime element right?
and a runtime element doesnt have a getElementName() but just getName()

If elem is a JSEvent then it should be getElementName() yes

Hi Johan,

thanks for the reply.
Basically I generate a new label with the solutionModel, when I drop the label it should return the name, the x and y position.

What I noticed is that in nonDesignMode it is no problem to get the name, but when the form is in clientDesignMode it doesn’t remember it anymore. I tried the same with a “normal” button and it’s the same story. So I guess that the designMode doesn’t allow the getElementName() function right?

I also tried the getName() function, but it returns an error: cannot find function getName.

Strange is that the event.getX() and event.getY() returns a right value.

now you suddenly talk about event.getX() and event.getY()
before it was elem.getElementName()
what was elem??

What kind of event are we talking here about, what is your code?

Ok, this is the code to create the label

CODE: SELECT ALL
// "labelText is a global variable where I can put the name of the label
var form = solutionModel.getForm('contacts_profile')
   var label = form.newLabel(globals.labelText,0,10,80,20)
   label.transparent = true
   label.name = globals.labelText
  
   forms.contacts_profile.controller.recreateUI()

and this is the on Drop function

function onDrop(event)
	var name = event.getElementName()
	var x = event.getX()
	var y = event.getY()
	
	application.output(name)

Before I used “elem” just in the place of “event”, it shouldn’t be a problem right? Whatever I use “name” returns null.

ok thats the ondrop of design mode right?
The you dont have an element name because you always only drop on the forum

What you do have is

event.data

which is an array of elements that where selected for the drop, so

var name = event.data[0].getName()

is your name of the the first element that is dragged.

Life is so simple when you know all the answers.

Thank you, it works.