Professional Documents
Culture Documents
In my
previous post on setting up predelivered collaborative related services, I was asked to also elaborate on how to create your
own custom related content based on field content from the component. In this post I will explain how to incorporate Google Maps directions as related content based on the home address of an employee and the work location. For this example I will be using PeopleSoft HCM9.1 on PeopleTools 8.51. First lets examine the Google Maps direction service. You can invoke directions straight from an url using start location and end location parameters. Base url looks like this: http://maps.google.com/maps?saddr=[startlocation]&daddr=[endlocation] You can see that url has two variables consisting of the start and end location. For example if you would construct the following url: http://maps.google.com/maps?saddr=Oracle, San Francisco&daddr=Duboce Avenue, San Francisco You will end up with following:
We will use this base url to set up a related content service in PeopleSoft and expend this url with the work and home location of an employee on the Home and Mailing Address page.
In the screen above you will see an extra parameter output. This has to have a fixed value ofembed. This is a requirement from Google, if you want to use Google Maps in junction with iFrames. Now we need to have access to the home and work location. I will add this service to the Home and Mailing Address page. Here we have access to the home address and upon changing your home address you will see a new direction being generated.
This page contains the Home address. To be able to invoke Google Maps directions, we will have to fetch and add the work location to this page. I will store the work location in a derived record and add it to the page level 0.
First lets have a look at the current work location of the employee.
Now that we know the home and work location the final url that the Related Content Service will construct will be http://maps.google.com/maps?saddr=643 Robinson St, Buffalo&daddr=500 George Washington Pkway, New York First start by creating a derived record to store the from and to location like below
Now add field FROM_LOCATION to level 0 and add Component PeopleCode PostBuild Event, to store the work location from the current job assignment. It is important to set the style of the field to PTRANSPARENT. This style will make the field invisible for the eye but accessable for the Related Content Service.
Code will be something like this: Local Record &Job, &Location; /* Get current assignment */ &Job = CreateRecord(Record.CURRENT_JOB); &Job.EMPLID.Value = HR_SS_PERS_SRCH.EMPLID.Value; &Job.EMPL_RCD.Value = 0; &Job.EFFSEQ.Value = 0; &Job.SelectByKeyEffDt(%Date);
/* Get location details */ &Location = CreateRecord(Record.LOCATION_TBL); &Location.SETID.Value = &Job.SETID_LOCATION.Value; &Location.LOCATION.Value = &Job.LOCATION.Value; &Location.SelectByKeyEffDt(%Date);
&Address = GetLevel0()(1).GetRowset(Scroll.PERSON_ADDRESS);
For &i = 1 To &Address.ActiveRowCount If &Address(&i).PERSON_ADDRESS.ADDRESS_TYPE.Value = "HOME" Then GOOGLEDIREC_DER.FROM_LOCATION.Value = &Address(&i).PERSON_ADDRESS.ADDRESS1.Value | ", " | &Address(&i).PERSON_ADDRESS.CITY.Value; End-If; End-For;
Click on Assign Related Content to Application Pages and you will be presented with the PeopleSoft Portal menu.
From here choose the ESS Home and Mailing Address component.
On this page set Services at Page level, because we only want to see the Related Content on the main page and every time you change your address the Related Content needs to be refreshed with the home address field filled in the PageActivate. Choose Page HR_HOME_MAILING and service GOOGLEMAPSDIRECTIONWORKHOME. Click on Configure to assign the fields on the page to the service parameters.
For service parameter Home Location set Mapping Type to Page Field and click in Select. In the popup screen, choose From location from the derived record. Do the same for service parameter Work Location and set it to field To location. Set service parameter Embed output to mapping type Fixed and enter the value embed. The screen will look like this.
See it in action
All configuration is now done. Navigate to the Home and Mailing Address component and you will see that you now have a Related Content dropdown on the page.
When you select the Related Content HomeWorkDirection the screen splits and you will see Google Maps in the second frame.
Now lets say we want to move closer to work and we change the home address
In this post I have still created some customization, because the data in my component was not complete to call this service. The entire idea of Related Content is that you do not have to create any customization to make it work. Always try to keep the number of customization to a minimum.