Skip to content

Commit f1ef2a0

Browse files
Create Prompt for make attachment mandatory based on variables (#84)
1 parent b548729 commit f1ef2a0

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Here's a ServiceNow GenAI prompt to generate code that makes an attachment mandatory based on a variable's value:
2+
3+
4+
---
5+
6+
ServiceNow GenAI Prompt:
7+
8+
"Generate a client-side script for a ServiceNow catalog item form that makes file attachments mandatory based on the value of a choice variable. If the user selects 'Yes' from the choice variable (e.g., variable name: 'attachment_required'), the system should prevent form submission and display an error message unless an attachment has been added."
9+
10+
11+
---
12+
13+
This prompt will help the Generative AI generate a client-side script (likely JavaScript/GlideForm) that can be added to your catalog item for enforcing this condition.
14+
15+
Alternatively, here's a sample script you can use directly:
16+
17+
Sample Client Script (onSubmit)
18+
19+
function onSubmit() {
20+
var attachRequired = g_form.getValue('attachment_required'); // 'attachment_required' is the variable name
21+
if (attachRequired == 'Yes') {
22+
var attachments = g_form.getAttachments();
23+
if (attachments.length == 0) {
24+
g_form.addErrorMessage('Attachment is mandatory when you select "Yes". Please attach a file before submitting.');
25+
return false; // Prevent form submission
26+
}
27+
}
28+
return true;
29+
}
30+
31+
Variable Name: Change 'attachment_required' to match the actual name of your variable.
32+
33+
Condition: Adjust the if (attachRequired == 'Yes') part if you have different options for the variable.
34+
35+
36+
This will display an error and prevent the form submission if there are no attachments when the user selects "Yes" in the specified choice field.
37+

0 commit comments

Comments
 (0)