Expand my Community achievements bar.

SOLVED

How do I find form name?

Avatar

Level 2

Hello,

Trying to figure out the form name, but not getting desired result with the following:

if (xfa.form.name == "form050") then

.
.
.
Any suggestions?  Thanks.
-Veni

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Your code fails because of "then", which isn't javascript.

I.e. the line fails silently, which I find quite odd. If not an exception, the js engine should at least generate a syntax error. What happens is that it simply continues execution.

This produces the same behaviour:

if (false) askldalksdjhaldh
{ app.alert("you should never see this message."); }

This produces an error (as it should):

if (false) askldalksdjhaldh { app.alert("you should never see this message."); }

View solution in original post

8 Replies

Avatar

Former Community Member

One way is to add the name of the form as the title in the form properties. You can then reference "xfa.host.title".

Untitled.png

Steve

Avatar

Level 2

Thanks for the suggestion, but my if statement still fails to execute properly after I changed my form properties to:

FL-335 Properties.png

and changed my code to:

if (xfa.host.title == "MC-050") then

{

xfa.host.messageBox("In == mc050, UPPERcase p section ALNvali.","Error"); // vh

What happens is that the comparison I make (above), even though the title does NOT equal MC-050, determines the title to be equal and I get my message to pop up.  Just to test, I added the following to verify the title:

xfa.host.messageBox(xfa.host.title,"Error"); // vh

and it did in fact yield:
FL-335 Properties Test.png
So I'm not sure why the comparison isn't working properly.  Thanks for your help.
-Veni

Avatar

Former Community Member

This works for me....

// form1.page1.btn::click - (JavaScript, client)


if (xfa.host.title == "HowTheHeck.pdf") {

  xfa.host.messageBox(xfa.host.title);

}

else {

  xfa.host.messageBox("Not HowTheHeck.pdf");

}

Steve

Avatar

Level 2

What if you switch your comparison value after the == to say, "Form.pdf" or some value not equal to what your form title is?  I ran into this because initially my test was just like yours where I had the "nice" or expected comparison that should work, but then I found out that my 'else' portion was never being accessed because the first equality comparison was somehow ALWAYS true.  Thanks.

Avatar

Correct answer by
Former Community Member

Your code fails because of "then", which isn't javascript.

I.e. the line fails silently, which I find quite odd. If not an exception, the js engine should at least generate a syntax error. What happens is that it simply continues execution.

This produces the same behaviour:

if (false) askldalksdjhaldh
{ app.alert("you should never see this message."); }

This produces an error (as it should):

if (false) askldalksdjhaldh { app.alert("you should never see this message."); }

Avatar

Level 2

Oh no!  That means I got a lot of code to go through and fix....not good!  >:-<

I really wish they'd address this -- I can't imagine being the only one that's ran into this "silent fail" issue with SmartForms and JavaScript.

I'll change my code and see if it all works now. 

Thanks for the tip!!!

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----