Author Archive: Stefan Cameron

Flag Mandatory Fields Automatically

If you would like to use script in your forms in order to automatically flag mandatory fields, using a red asterisk (*) in their captions, check-out this article I just posted on my blog.

The script supports mandatory fields with the following characteristics:

  • have plain or rich text captions
  • have no captions (no asterisk is displayed in this case)
  • use text objects (plain or rich text) as captions instead of normal field captions
  • have the same name (multiple instances that aren’t dynamically generated)
  • are inside repeating subform instances

Typically called when the root subform is initialized, the script will search recursively (depth-first search) for all fields within a specified container (i.e. the root subform) and will place the asterisk on any mandatory field it finds. There is also a function by which the asterisk can be toggled on/off by explicitly telling the function whether to treat the field as mandatory or optional.

The script is located in a script object. The idea is that you would make a script object fragment out of it and re-use it in any form that needs this functionality. The script is also heavily commented so it should be relatively easy to extend for your own needs.

Saving a Generic Form Resource to the LiveCycle Repository

I found myself suggesting this as a possible solution on another thread today and thought it could be generally useful.

Here’s how you would use the CM API to create a new generic form resource, stuff your form template content into it and save it to the LiveCycle Repository using the currently-posted release:

import cm.model.CmObject;
import cm.model.CmSession;
import cm.model.repository.CmResourceType;
import cm.model.repository.CmRepositoryEvent;
import cm.model.repository.CmRepositoryFactory;
import cm.model.repository.CmResourceCollection;
import cm.model.repository.ICmRepository;

private function onBtnClick(event:Event):void
// create a new generic form template resource object
var xdp:CmObject = new CmObject();
xdp.resourceType = CmResourceType.FORM_TEMPLATE;
xdp.path = "/cm/content/myForm.xdp";
xdp.contentType = "application/vnd.adobe.xdp+xml";
xdp.contentData = '<xdp><template><subform name="root"><subform name="page"><field/></subform></subform></template></xdp>';

// make sure there's an active, authenticated session
// (note that username, password, server and port are variables you would supply)
if (CmSession.getInstance() == null || !CmSession.getInstance().authenticated)
CmSession.createInstance(username, password, server, port);

// get an instance of the LC Repository
var rep:ICmRepository = CmRepositoryFactory.getInstance();

// save it in the LC Repository, true, onSave, onSaveFault);

private function onSave(event:CmRepositoryEvent):void
{"Saved XDP to LC Repository");

private function onSaveFault(event:FaultEvent):void
{"Error occurred while attempting to save: " + event.fault.toString());