Changing PortalRegistry Properties
This example shows how to change the default template used by a PortalRegistry. The following is the complete code sample: the steps explain each line.
Local ApiObject &MySession;
Local ApiObject &MyPortal, &MyPortalColl;
/* Access the current session */
&MySession = %Session;
If NOT &MySession Then
/* do error processing */
End-if;
&MyPortalColl = &MySession.FindPortalRegistries();
For &I = 1 to &MyPortalColl.Count
&MyPortal = &MyPortalColl.Item(&I);
If &MyPortal.DefaultTemplate = "HR99" Then
&MyPortal.DefaultTemplate = "HR00"
&MyPortal.Save();
End-If
End-For;To change PortalRegistry properties:
-
Get a Session object.
Before you can access a PortalRegistry object, you must get a session object. The session controls access to the registry, provides error tracing, enables you to set the runtime environment, and so on. Because you want to use the existing session, use the %Session system variable (instead of the GetSession function.)
&MySession = %Session; -
Get a PortalRegistry collection.
Use the FindPortalRegistries method with no parameters to return a collection of all the PortalRegistries because you want to check all the registries for the invalid template.
&MyPortalColl = &MySession.FindPortalRegistries();Use the Count property on the collection to loop through all the registries.
For &I = 1 to &MyPortalColl.Count -
Get a PortalRegistry object.
You can access a PortalRegistry object from the PortalRegistry collection using the Item method.
&MyPortal = &MyPortalColl.Item(&I); -
Check for the invalid template and correct if necessary.
Use the DefaultTemplate property both to check for the invalid template name, and to set the correct template. Save the PortalRegistry when you make a correction.
If &MyPortal.DefaultTemplate = "HR99" Then &MyPortal.DefaultTemplate = "HR00" &MyPortal.Save(); End-If;
You may want to do error checking after you save the PortalRegistry.