cancel
Showing results for 
Search instead for 
Did you mean: 

How to read a context variable in formcalc

dstjacques
Participant
0 Kudos

I have a global variable in the context. That variable (type CHAR01) contains only "X" or space.

When the variable contains "X" one of the subform should hide.

The variable is not displayed in any subform.

Here is the Formcalc script I used without success at the subform initialize event.

if( HIDEFLAG eq "X") then

$.presence = "hidden"

endif

prabhjotsingh14
Active Participant
0 Kudos

First of all, drag the global variable HIDEFLAG in form context. This variable can be read directly in scripts without making it available in form layout. Trick is to use "value" property instead of "rawValue" as we want to access context variables.

If java script can be used, following code will work in INITIALIZE event of sub from:

var lv_data = xfa.resolveNode("$record.HIDEFLAG").value;
If( lv_data == "X") 
{
 this.presence = "hidden";
}

Accepted Solutions (1)

Accepted Solutions (1)

Hi Daniel,

Use below code.

If ( $record.variable == "X" ) then

condition...

Endif

Note - Variable name should be in capital letters

Answers (3)

Answers (3)

dstjacques
Participant
0 Kudos

For the benefits of all.

As Antoine suggested, the variable has to be part of the subform you are working in.

The "presence" property, found in the Object->Fleds tab, can be changed from visible to hidden.

So the variable will not be display but can be used by the Formcalc or Javascript.

Example:

Is a subform named "PAGE1", a TextField "langu" is bind to a global variable and is containing "EN"

In the subform PAGE1 you need to hide another subform name "French", you can put in the initialized event of the subform "French" the following javascript:

if (this.resolveNode("langu").rawValue == "EN") {
this.presence = "hidden";
}
else this.presence = "visible";

dstjacques
Participant
0 Kudos

Hello Antoine

Using "this.rawValue" indicate the variable is somewhere in the form layout.

In my case that variable is not used in the layout. It has been created only to allow the layout to react based on the value in it.

A global variable "HIDEFLAG TYPE CHAR01" has been created at the interface level.

The initialization of the variable has been done in the initialization code.

CLEAR hideflag.

IF <condition>.

hideflag = 'X'.

ENDIF.

The Global variable has been included in the context of the form.

That variable is not display anywhere in the form. It has been created only to use it to hide some subforms.

Regards

Daniel

antoine_foucault
Active Contributor
0 Kudos

Hi Daniel,

It depends where the variable is placed in the scheme.

If you don't mind JavaScript over FormCalc, here are some examples:

this.rawValue == 'X' or this.rawValue <> null

this.parent.rawValue == true

this.parent.parent.rawValue etc...

if (this.SW_PRINT_SUPPLEMENT.rawValue == null )

{ this.presence = "hidden";

}

Best,

Antoine