How to solve the following Error ?

Hi

I write the javascript in velocity file like

"#if($document.form.userNameContains.value == ($element.getName()));"

when i run this i got the following error , please tell me the solution to this error

($document.form.userNameContains.value) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. templates/allusers.vm [line 24, column 69]

2 answers

As Ive said previously, you are mixing server side and client side concepts, velocity != javascript.

Prefixing a # indicates that it is a velocity directive, this runs on the server and dissapears by the time it gets to the client. What you are seeing as a server side validation failure, because $document cannot be resolved on the server.

Perhaps you could explain what you are trying to achieve? Where is this velocity triggered from, an action? Perhaps you are looking for the current user that is available (if driven by an action) via $action.getLoggedInUser(), then you can use the various methods on the user for your comparison.

0 vote
Mizan Community Champion Dec 13, 2012

Try #if($document.form.userNameContains.value.equals($element.getName()));

Also check if both the values are not null

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

240 views 4 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you