Skip to content

Commit 5cd3797

Browse files
authored
Merge pull request #3316 from kasperbolarsen/develop
Added scenario for Birthdays and work Anniversaries
2 parents 221fa85 + a9b6754 commit 5cd3797

File tree

11 files changed

+153
-1
lines changed

11 files changed

+153
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
A common requirement for intranets is to show birthdays of employees.
3+
And as the SharePoint User Profile Application has a property for birthdays, it is a natural choice to use search to show birthdays of employees.
4+
5+
(as of writing this (2023), the Graph API does not have a property for birthdays, so we can't use the Graph API to get the information)
6+
7+
8+
9+
The tricky part is that in the User profile application the birthday value is store is a rather usual datatype "date no year"
10+
11+
![Birthday in the User Provisioning Service](../assets/../scenarios/assets/Setup-Results-web-part-to-show-birthdays/BirthdayUPA.png)
12+
13+
14+
In my tenant the SPS-Birthday property was mapped to RefinableDate00 and the actual value in the property is 2000-[the date]:
15+
16+
![Managed Property value](../assets/Setup-Results-web-part-to-show-birthdays/refinabledate00.png)
17+
18+
(use the magnificent [SP Editor tool](https://chrome.google.com/webstore/detail/sp-editor/ecblfcmjnbbgaojblcpmjoamegpbodhd) or [SP Search Query Tool](https://github.com/pnp/PnP-Tools/blob/master/Solutions/SharePoint.Search.QueryTool/README.md) to inspect the managed properties)
19+
20+
21+
22+
So, the query had to be something like "those accounts where RefinableDate00 = 2000 + the value of today's date
23+
24+
25+
26+
In KQL we have the token "today" that will give us today's date, but as far as I know, we can't get the components the date consist of, like Month and Day.
27+
28+
Luckily, the PnP Modern search provides additional Tokens, see [Tokens](https://microsoft-search.github.io/pnp-modern-search/usage/search-results/tokens/)
29+
30+
31+
32+
So the final query is:
33+
34+
**RefinableDate00=2000-{CurrentMonth}-{CurrentDate}T00:00:00Z**
35+
36+
37+
38+
( and of cause a criteria to exclude former employees, like SPS-HideFromAddressLists<>1)
39+
40+
![Birthday web part](../asserts/../scenarios/assets/Setup-Results-web-part-to-show-birthdays/birthdays.png)
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
Getting PnP Modern Search to show work anniversaries should be easy enoght, right? Just add a couple of managed properties and a couple of web parts and you are done. Well, not quite.
3+
4+
The problem is that date manipulation in KQL is hard at best and sometimes impossible. In order to find a work anniversary you must compare Today and the Hiredate managed property, but ONLY the day and month part.
5+
6+
Calculating how many years the employee has been with the company is also required and it seems like there is no way to get that using KQL.
7+
8+
![upa](../scenarios/assets/Setup-Results-web-part-to-show-work-anniversaries/upa.png)
9+
10+
## Objective
11+
12+
We want to be able to display two options:
13+
- Employees having a work anniversary today, and also how many years they have been with the company
14+
- Employees having a work anniversary within the next 7 days + number of years.
15+
16+
## How to cheat
17+
In order to achieve the objectives, I had to get:
18+
- The account
19+
- The hiredate, but with the year segment being the current year
20+
- The number of years the employee has been with company at the next anniversary
21+
22+
![birthdayAndHiredateSynclist](..\assets\Setup-Results-web-part-to-show-work-anniversaries\BirthdayAndHiredateSyncList.png)
23+
24+
Lets add birthdayThisYear while I was at it, in order to be able to show upcoming birthdays.
25+
26+
27+
The basic idea is that we want to change the hiredate from eg. 10/26/2005 to 10/26/2023 as that allows us to compare Today with this value 😀
28+
(RefinableDate12 is mapped to the HiredateThisYear property)
29+
30+
Who is having a work anniversary today?
31+
32+
*RefinableDate12=Today*
33+
34+
Anniversary within the next x days is also a piece of cake:
35+
36+
*RefinableDate12<{Today+7} AND RefinableDate12>{Today}*
37+
38+
## Implementation
39+
Asking the intern to keep the list above in sync would be a cruel and unusual punishment, and hence actually forbidden in the USA, something to do with a constitution or something like that.
40+
41+
The list should of course be synced with the source, in this case the User Profile Application, at least once each month. The reason I am not using Graph is that birthday is not in the schema.
42+
43+
![mapping birthday and hiredate](../scenarios/assets/Setup-Results-web-part-to-show-work-anniversaries/mapping1.png)
44+
45+
**Prereq: Map SPS-Birthday and SPS-Hiredate to RefinableDate00/01 or similar**
46+
47+
Once data is showing up in those RefinableDate properties you should be ready to create the list.
48+
Grab the script here . It will create a few Site Columns and a Content type on the site collection of your choosing. The list is then created, and the Content type added to the list.
49+
The Add-UserDataToList function will query the UPA for accounts and write the data we need to the list.
50+
51+
Hit the Reindex site in the site collections Search and Offline Availability section for the site columns to be picked up by search.
52+
53+
Map the crawled properties to a couple of RefinableDates. If possible it is recommended to make this mapping on the tenant level as it ensures that you can use them in your entire tenant.
54+
![mapping birthdaythisyear and hiredatethisyear](../scenarios/assets/Setup-Results-web-part-to-show-work-anniversaries/mapping2.png)
55+
Find the Content Type ID of the Content type created by the script.
56+
57+
58+
Add a Results web part, name it "Todays work anniversaries"
59+
60+
Set the Query template to:
61+
62+
*Contenttypeid:0x01009290F0FA40E7CB42B55D6D96F897262B\* RefinableDate12=Today*
63+
64+
*(replace 0x01009290F0FA40E7CB42B55D6D96F897262B with the value for the your content type)*
65+
66+
Add a Results web part, name it "Upcoming anniversaries (7 days)"
67+
68+
Set the Query template to:
69+
70+
*Contenttypeid:0x01009290F0FA40E7CB42B55D6D96F897262B\* RefinableDate12<{Today+7} AND RefinableDate12>{Today}*
71+
72+
*(replace 0x01009290F0FA40E7CB42B55D6D96F897262B with the value for your content type)*
73+
74+
75+
76+
Add the managed properties birthdayhiredateAccountOWSUSER, nextWorkAnniversaryInYearsOWSTNMBR, RefinableDate10, RefinableDate12 to the Selected Properties in both web parts.
77+
78+
Enter Layout slots
79+
80+
Change UserEmail to use the birthdayhiredateAccountOWSUSER property
81+
82+
Change Date from Created to RefinableDate12
83+
84+
For both web parts you can select the People layout on "page 2" in the web part configuration.
85+
86+
Set Secondary text to:
87+
88+
{{{Title}}} has been with us {{{nextWorkAnniversaryInYearsOWSTNMBR}}} years
89+
90+
(remember to click Use Handlebars expression)
91+
92+
Set Tertiary text to:
93+
94+
{{getDate (slot item @root.slots.Date) "MMMM-D"}}
95+
96+
(remember to click Use Handlebars expression)
97+
98+
Set the sorting on the Upcoming Anniversaries to RefinableDate12 asc
99+
100+
Run the Add-UserDataToList function in a runbook or similar once a month and you should be done😊 Near the end of the year you might need to run is once per day.
101+
102+
![final result](../scenarios/assets/Setup-Results-web-part-to-show-work-anniversaries/anniversaries.png)
Loading
Loading
Loading
Loading
Loading
Loading
Loading

docs/scenarios/index.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,19 @@ With the Modern Search Web Parts you can create a simple and useful Department W
4848
## [Use query rules for promoted links](Use-query-rules-for-promoted-links.md)
4949
With the Modern Search Web Parts you can show promoted links for important results. They will be configured with query rules in the SharePoint Search Admin Center. Promoted results will show users more informations and direct links about specific, predefined, terms they searching for.
5050

51-
## [Use query string from URL for dynamic search](use-query-string-in-url.md)
5251
This scenario describes how to use query string as value in the URL from the current page. You can use URL query string parameters to build dynamic search pages.
5352
Use a library with metadata that you can use the query string parameter in the URL.
5453

54+
55+
56+
## [Setup Results web part to show birthdays](Setup-Results-web-part-to-show-birthdays.md)
57+
A common request in any intranet is to show birthdays of employees. This scenario describes how to use stock SharePoint search to show birthdays of employees in the search results.
58+
59+
60+
## [Setup Results web part to show work anniversaries](Setup-Results-web-part-to-show-work-anniversaries.md)
61+
62+
Showing the work anniversaries of employees is a common request in any intranet. This scenario describes one way to achive this using a sleight of hand trick/cheating as the search index does not contains the information we need.
63+
5564
---
5665

5766
More to come!

0 commit comments

Comments
 (0)