-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlowercase_to_title_case.js
42 lines (33 loc) · 1.24 KB
/
lowercase_to_title_case.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Script to convert the text in a source field to title case in a destination field
// Function to convert string to title case
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
// Get the table name from the user
let table = await input.tableAsync("Select the table");
// Get the source field from the user
let sourceField = await input.fieldAsync("Select the source field with keywords", table);
// Get the destination field from the user
let destinationField = await input.fieldAsync("Select the destination field for title case names", table);
let query = await table.selectRecordsAsync({
fields: [sourceField, destinationField]
});
let updates = [];
for (let record of query.records) {
let sourceValue = record.getCellValueAsString(sourceField);
let titleCaseValue = toTitleCase(sourceValue);
updates.push({
id: record.id,
fields: {
[destinationField.id]: titleCaseValue
}
});
}
// Perform the updates in batches
while (updates.length > 0) {
await table.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50);
}
output.markdown('Conversion to title case complete!');