Skip to content

Commit b3b00eb

Browse files
authored
Create Change Schedule Button on Change forms
UI Action script that opens a modal dialog to update the Planning Start Date and Planning End Date on a Change Request form. The script opens a modal window, allowing the Change Admin to update the fields. Sharing use a UI Action with a simple UI Modal setup.
1 parent 5136f36 commit b3b00eb

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//UI Action script that opens a modal dialog to update the Planning Start Date and Planning End Date on a Change Request form. The script opens a modal window, allowing the Change Admin to update the fields. Sharing use a UI Action with a simple UI Modal setup.
2+
//UI Action condition gs.hasRole('change_admin')
3+
function showModal() {
4+
// Define modal properties
5+
var dialog = new GlideModal('glide-modal-dialog');
6+
dialog.setTitle('Change Schedule');
7+
8+
// Add form to modal content
9+
var modalContent = `
10+
<form id="change_schedule_form">
11+
<div>
12+
<label for="start_date">New Planning Start Date:</label>
13+
<input type="date" id="start_date" name="start_date" value="${g_form.getValue('planned_start_date')}">
14+
</div>
15+
<br>
16+
<div>
17+
<label for="end_date">New Planning End Date:</label>
18+
<input type="date" id="end_date" name="end_date" value="${g_form.getValue('planned_end_date')}">
19+
</div>
20+
</form>
21+
`;
22+
dialog.setBody(modalContent, false, false);
23+
24+
// Add Save and Cancel buttons
25+
dialog.addFooterButton('Save', 'saveSchedule()', 'btn-primary');
26+
dialog.addFooterButton('Cancel', 'closeModal()', 'btn-default');
27+
28+
dialog.render();
29+
}
30+
31+
function saveSchedule() {
32+
var startDate = document.getElementById('start_date').value;
33+
var endDate = document.getElementById('end_date').value;
34+
35+
// Check if both dates are provided
36+
if (!startDate || !endDate) {
37+
alert('Please provide both Planning Start and End dates.');
38+
return;
39+
}
40+
41+
// Update the fields in the form
42+
g_form.setValue('planned_start_date', startDate);
43+
g_form.setValue('planned_end_date', endDate);
44+
45+
// Optionally, save the form
46+
g_form.save();
47+
48+
// Close the modal
49+
closeModal();
50+
}
51+
52+
function closeModal() {
53+
GlideModal.close('glide-modal-dialog');
54+
}
55+
56+
// Invoke the showModal function to display the modal
57+
showModal();

0 commit comments

Comments
 (0)