Tip>Designer

Dynamically create a mapping off the Dialogs plug-in

 

Article #:

0039

Contributor:

Daniel Todes

GF version:

4.0

Applies to:

Mappings and Dialog Answer-sets

Last updated:

April 5, 2002

Description

Test for the existence of a mapping off the Dialogs plug-in. If it does not exist, create it dynamically. You can also test for the existence of a Dialog Answer-set in the mapping.

Explanation

You can use scripting in FillPoints to test for the existence of a specific mapping off the Dialogs plug-in. If the mapping does not exist, you can create it dynamically.

Click here to view a step-by-step example.

  1. Set the variable values for the mapping name and the storage path:

%[DialogMappingName = Profiles.UserName & "Dialog Mapping"]

%[DialogMappingPath = "c:\" & Profiles.UserName & "\MyAnswerSets"]

 

NOTE

  • This path must already exist on the system.

  • Variables can be used in the path if necessary.

 

  1. Test to see whether the mapping already exists in the Dialogs plug-in. If it does not, you can create it dynamically:

%[DeleteBlockIf(Explorer.Application("Default").Plugin(Dialogs).Mappings.Exists(DialogMappingName))]

%[~Explorer.CreateMapping("Default", Dialogs, DialogMappingName, DialogMappingPath)]

%[EndBlock()]

  1. Refresh the mappings list (this ensures that the new mapping is available):

%[Explorer.Applications.Refresh]

  1. If you ever need to remove the mapping, you can use the following FillPoint:

%[~Explorer.RemoveMapping("Default", Dialogs, MappingName)]

 

You can also test for the existence of a Dialog Answer-set in the mapping. If the Answer-set exists, open it for editing; if it does not, create it dynamically.

Click here to view a step-by-step example.

  1. Store the name for the Dialog Answer-set in a variable:

%[AnswerSetName = "xyz"]

  1. Test to see whether the Answer-set already exists. If it does, open it for editing:

%[KeepBlockIf(Dialogs.Exists(DialogMappingName, AnswerSetName))]

%[X=Dialogs.Select(DialogMappingName, AnswerSetName)]

%[Dialogs.Edit(X)]

%[EndBlock()]

  1. If the Answer-set does not exist, create it from the "master" Dialog, save it to the new mapping name and then open it for editing:

%[DeleteBlockIf(Dialogs.Exists(DialogMappingName, AnswerSetName))]

%[X=Dialogs.New("\GF General Office Samples\Contacts", "xyz")]

%[X._Mapping=DialogMappingName]

%[Dialogs.Save(X, True)]

%[Dialogs.Edit(X)]

%[EndBlock()]