Search

Set Command – XpressDox

The Set command enables you to create default values on the interview, without the need for user intervention on the interview.

It is different to OnExitSet or OnEnterSet in that the cursor needs to exit or enter a field in order for the Set to execute.

 

 

Set a default value:

The following example sets the data element FullName to the contents of Name + Surname as entered by the user on the interview. The value of FullName can then be used elsewhere. There is no condition in this example of a Set command, hence the empty value inside ().

«Name» «Surname»
«FullName»
«Set(FullName,(),concat(Name,’ ‘,Surname))»

Suppose however, that FullName could consist of Name + Surname if the Entity is an Individual, or a Company Name is the Entity is a Company. This second example introduces a condition to the Set command.

«ChooseFromRDBList(Entity_type,Individual,Company)»
«if(Entity_type = ‘Individual’)»
«Name» «Surname»
«Else()»
«CompanyName»
«End()»
«FullName»
«Set(FullName,(Entity_type = 'Individual'),concat(Name,' ',Surname),CompanyName)»

 

Set default values but allow the user to amend them

«Comment(ask about changing the default answers but make the default answer to this question No)»
«ChooseFromHzRDBList(Change_defaults,,Yes,No)»
«SetInitialValue(Change_defaults,No)»
«CaptureDataElement(Change_defaults)»«Comment(this is forcing relevance)»
«Comment(also make them read-only unless the user clicks Yes)»
«ReadOnly(Managing_Partner_hourly_rate,Junior_Partner_hourly_rate,Change_defaults = ‘No’)»
«Comment(the values)»
«FormatNumber(Managing_Partner_hourly_rate)»
«FormatNumber(Junior_Partner_hourly_rate)»
«Comment(they have default values. Note that without the condition Managing_Partner_hourly_rate = ‘’ the amount cannot be changed)»
«Set(Managing_Partner_hourly_rate,(Managing_Partner_hourly_rate = ''),800)»
«Set(Junior_Partner_hourly_rate,(Junior_Partner_hourly_rate = ''),500)»

Another application for this command is that you want to set default values for the users, but also make provision for them to change those values if they need to. Suppose there are default rates for certain services provided by your firm.

 

 

Combine the Set command with other functions

 

IncrementDate (Date of birth)

As an example, suppose you have an interview that requires the user to enter a number of items of personal information, such as first name, last name and date of birth. Here is a very simple template:

«FirstName» «LastName»
«FormatDate(DateOfBirth,'o MMMM yyyy')»

Somewhat annoyingly, many systems will present a calendar for the capture of a date of birth which require the user to scroll or tab through a list of years starting with the current date. This is only useful when capturing a date of birth of a very young child. In the case of the user’s own date of birth, it is far more likely to be at least 20 years in the past. The Set command will help you present a nicer calendar starting point to the user:

«FirstName» «LastName»
«FormatDate(DateOfBirth,'o MMMM yyyy')»
«Set(DateOfBirth,(DateOfBirth = ''),IncrementDate(Today(),-20,'y'))»

You can read the command as saying, “If the DateOfBirth data element is empty (DateOfBirth = ''), then set it to 20 years ago from today”.

The condition is the same as our second example; if DateOfBirth = ” then the user can change the value.

 

YearsBetween (Calculate the age)

Once you know the date of birth, then you can calculate the person’s age. The following will show how to calculate the age in years:

«Set(Age,(),YearsBetween(Today(),DateOfBirth))»

Note the empty condition in this example i.e. the empty (). That means that the Age data element will ALWAYS have the value as calculated.

To see this in action, make a template like the above sample, and include the two Set commands, and an «Age» fillpoint. Then run the template. You should notice the following:

  • The DateOfBirth should start off as 20 years in the past.
  • The Age data element will have the value 20.

Try to change the Age. It should not change. At least, it will change and then revert to 20 once you exit the field in the interview.

Change the date to your own date of birth – the Age should then be your age, although it will probably include a fractional part. You could do the following to get the Age to be a bit more like we usually quote our age:

«Set(Age,(),floor(YearsBetween(Today(),DateOfBirth)))»

Or, insurance companies like to use “age next birthday”, which would then be:

«Set(Age,(),ceil(YearsBetween(Today(),DateOfBirth)))»

 

Execute many Set commands inside a block – The With command

This article provides information on how to execute many Set commands with the same condition.