Expand my Community achievements bar.

SOLVED

Displaying a default value when no value exists

Avatar

Level 2

We are using XFA forms to generate formatted output from a quality management system. I'm trying to modify the form to display a "No Value" message when there is no data from the system to output.

I have some javascript to check the values:

{

if ((oField.rawValue == null) || (oField.rawValue == "")) {

oField.rawValue="No Value";

}

else

{ oField.rawvalue;}

}

But I am having trouble figuring out how to add it to my form. I'm using designer 6.4. Any suggestions?

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi,

As Mayank has suggested it would be valuable and I would say a best practice to reuse your code here. You can use a ScriptObject, and write your function there and call it from each of the fields that use it, and you can further extend this to be used by other forms by creating a scriptObject fragment to be stored in your fragment library.

Script Objects and Fragments are discussed and documented here in these Designer help documents:

https://helpx.adobe.com/content/dam/help/en/experience-manager/6-4/forms/pdf/scripting-reference.pdf

https://helpx.adobe.com/content/dam/help/en/experience-manager/6-4/forms/pdf/using-designer.pdf

Script fragments

A script fragment contains reusable JavaScript functions or values that are stored separately from

a particular object, such as a date parser or a web service invocation. These fragments include a

single script object that appears as a child of variables in the Hierarchy palette. Fragments

cannot be created from scripts that are properties of other objects, such as event scripts like

validate, calculate, or initialize.

For more information, see UsingScript Fragments.

RELATED LINKS:

Fragment Library palette menu Binding fragments to a data source

Using choice subform sets

View solution in original post

3 Replies

Avatar

Level 2

So I figured it out but I could use some more advice.

I made a text field a calculated read only field with a calculation script. Once I added my javascript it worked fine.

if ((myfield.rawValue == null) || (myfield.rawValue == "")) {

myfield.rawValue = "No Value";

}

I have approximately 30 fields in my form I would need to code this for. Would creating a function be better than adding this script to each field?

Avatar

Employee Advisor

Hi,

Creating a function would help in this case as you have many fields to evaluate for the same condition. If it would have been less no. of fields and you needed to add any further field-specific validation then you can add individual script also. 

Thanks,

Mayank

Avatar

Correct answer by
Employee

Hi,

As Mayank has suggested it would be valuable and I would say a best practice to reuse your code here. You can use a ScriptObject, and write your function there and call it from each of the fields that use it, and you can further extend this to be used by other forms by creating a scriptObject fragment to be stored in your fragment library.

Script Objects and Fragments are discussed and documented here in these Designer help documents:

https://helpx.adobe.com/content/dam/help/en/experience-manager/6-4/forms/pdf/scripting-reference.pdf

https://helpx.adobe.com/content/dam/help/en/experience-manager/6-4/forms/pdf/using-designer.pdf

Script fragments

A script fragment contains reusable JavaScript functions or values that are stored separately from

a particular object, such as a date parser or a web service invocation. These fragments include a

single script object that appears as a child of variables in the Hierarchy palette. Fragments

cannot be created from scripts that are properties of other objects, such as event scripts like

validate, calculate, or initialize.

For more information, see UsingScript Fragments.

RELATED LINKS:

Fragment Library palette menu Binding fragments to a data source

Using choice subform sets