Technical Test: SharePoint, C#, and JavaScript
Section 1: SharePoint
Question 1: Power Automate Approval Flow
Steps to create the approval flow in Power Automate:
1. Trigger: "When a file is created" from the specific document library.
2. Add approval action for the Manager.
- Action: "Approve or Reject"
- Assign it to the Manager (static or dynamic email).
3. Condition to check Manager approval: If approved, continue; otherwise, end the flow.
4. Add approval action for the Director.
5. Condition to check Director approval: If approved, update the 'Status' field in SharePoint
to 'Approved', otherwise, end the flow.
6. Use "Update file" action to modify the 'Status' field.
7. Finish the flow by sending a notification to the requester.
Question 2: [Link] to Display Latest 5 News
```javascript
import { sp } from "@pnp/sp/presets/all";
async function fetchLatestNews() {
try {
const news = await [Link]
.getByTitle("Noticias")
.items
.select("Title", "Created")
.orderBy("Created", false)
.top(5)
.get();
[Link]("Latest news:", news);
return news;
} catch (error) {
[Link]("Error fetching news:", error);
}
}
fetchLatestNews();
```
Section 2: C#
Question 1: GetDocumentMetadata
```csharp
using [Link];
using System;
using [Link];
class SharePointExample
{
public static void GetDocumentMetadata(string siteUrl, string username, string
password)
{
try
{
SecureString securePassword = new SecureString();
foreach (char c in password) [Link](c);
using (var context = new ClientContext(siteUrl))
{
[Link] = new SharePointOnlineCredentials(username,
securePassword);
var list = [Link]("Docs");
CamlQuery query = [Link]();
ListItemCollection items = [Link](query);
[Link](items);
[Link]();
foreach (var item in items)
{
[Link]($"Title: {item["Title"]}, ID: {item["ID"]}, URL:
{item["FileRef"]}");
}
}
}
catch (Exception ex)
{
[Link]($"Error: {[Link]}");
}
}
}
```
Question 2: FileLogger
```csharp
using System;
using [Link];
public class FileLogger : ILogger
{
private readonly string _filePath;
public FileLogger(string filePath)
{
_filePath = filePath;
}
public void Log(string message)
{
try
{
string logMessage = $"{[Link]}: {message}";
[Link](_filePath, logMessage + [Link]);
}
catch (Exception ex)
{
[Link]($"Error writing to log: {[Link]}");
}
}
}
```
Section 3: JavaScript
Question 1: validateFormData
```javascript
function validateFormData(formData) {
const errors = [];
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const phoneRegex = /^\d{10}$/;
const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
if () [Link]("Email is invalid");
if () [Link]("PhoneNumber is invalid");
if () [Link]("Date is invalid");
return {
isValid: [Link] === 0,
errors,
};
}
// Example usage:
const formData = {
Email: "example@[Link]",
PhoneNumber: "1234567890",
Date: "2025-01-01",
};
[Link](validateFormData(formData));
```
Question 2: API REST for Button in SharePoint
```javascript
[Link]("updateStatusButton").addEventListener("click", async () => {
const payload = { status: "approved" };
try {
const response = await fetch("/api/updateStatus", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: [Link](payload),
});
if ([Link]) {
alert("Status updated successfully!");
} else {
alert("Error updating status.");
}
} catch (error) {
[Link]("Error:", error);
alert("Error updating status.");
}
});
```