Something is breaking this script

Avatar

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile
ScottDM
Level 1

16-04-2018

I've got a dead simple script that hides and shows a subform based on the value of a checkbox:

if (this.rawValue == 1) {

form1.Page.NextYearSubform.NYSubform.presence = "visible";

}

else {

form1.Page.NextYearSubform.NYSubform.presence = "hidden";

}

This works fine if it is the first event upon opening the form. But if any other click event fires (the form has lots of checkboxes and radio buttons), this script ceases to work. Anyone seen this before?

Thanks.

Accepted Solutions (0)

Answers (7)

Answers (7)

Avatar

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile
ScottDM
Level 1

16-04-2018

I've never needed quotes before, and like I said the script obviously runs because the xfa.host.messageBox statement works.

So it's something in the form that is preventing the script from setting the presence property of the subform. Perhaps something is scrambled in the XML, which I would be useless at debugging.

Not a big deal... I've worked around it by removing the objects from the subform.

Thanks.

Avatar

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

16-04-2018

Weird.

Do you need to have quotes around the value?

When you use the action builder, it uses quotes.

1467072_pastedImage_0.png

Avatar

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile
ScottDM
Level 1

16-04-2018

I can test it with messageBox, so I know the script executes, but the property doesn't get set.

if (this.rawValue == 1) {

xfa.host.messageBox("One");

form1.Page.NextYear.NYSubform.presence = "visible";

}

if (this.rawValue == 0) {

xfa.host.messageBox("Zero");

form1.Page.NextYear.NYSubform.presence = "hidden";

}

Avatar

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile
ScottDM
Level 1

16-04-2018

I tried it with two ifs and it still wouldn't set presence = "visible".

Very strange.

Avatar

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile
ScottDM
Level 1

16-04-2018

So two ifs rather than an if with an else.

Is else known to be unreliable?

Avatar

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

16-04-2018

So there is no confusion in livecycle, i always make sure when i have if (this.rawValue == 1) that i always have if (this.rawValue == 0) rather than just an else.

Avatar

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
ScottDM
Level 1

Likes

0 likes

Total Posts

22 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Affirm 1
View profile
ScottDM
Level 1

16-04-2018

I fixed it by referencing the objects directly rather than hiding/showing the subform that contained them:

if (this.rawValue == 1) {

Title.presence = "visible";

Grade.presence = "visible";

Year.presence = "visible";

}

else {

Title.presence = "hidden";

Grade.presence = "hidden";

Year.presence = "hidden";

}

...But if anyone can explain why hiding/showing the subform didn't work I'd like to know.

Thanks.