- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2023 03:46 AM
Hi All,
I have a select box type varibale called Request required, If the varibale value is Manage documnet,then the Add attachment will be mandatory with a message, I have ceated a onsubmit client script with the below script, I am able to show the message, but not the able to make attachment mandatory,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if((g_form.getValue('request_required') == 'Manage document') && this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage(getMessage('attachment_is_mandatory'));
return false;
}
}
Can anyone help me out on this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2023 03:57 AM
I created blog few years ago; check that and enhance it further
Verify Mandatory Attachments Count on Catalog Item
ensure you use correct choice value for Manage document
function onSubmit() {
//Type appropriate comment here, and begin script below
var countRequired = 1;
if(g_form.getValue('request_required') == 'Manage document'){
if(window == null){
// portal
if(this.document.getElementsByClassName('get-attachment').length != countRequired) {
g_form.addErrorMessage(getMessage('attachment_is_mandatory'));
return false;
}
}
else{
// native view
var length = $j("li.attachment_list_items").find("span").length;
if(length != countRequired){
g_form.addErrorMessage(getMessage('attachment_is_mandatory'));
return false;
}
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2023 03:51 AM
this is for normal form or catalog form?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2023 03:54 AM
@Ankur Bawiskar - This is for catalog form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2023 03:57 AM
I created blog few years ago; check that and enhance it further
Verify Mandatory Attachments Count on Catalog Item
ensure you use correct choice value for Manage document
function onSubmit() {
//Type appropriate comment here, and begin script below
var countRequired = 1;
if(g_form.getValue('request_required') == 'Manage document'){
if(window == null){
// portal
if(this.document.getElementsByClassName('get-attachment').length != countRequired) {
g_form.addErrorMessage(getMessage('attachment_is_mandatory'));
return false;
}
}
else{
// native view
var length = $j("li.attachment_list_items").find("span").length;
if(length != countRequired){
g_form.addErrorMessage(getMessage('attachment_is_mandatory'));
return false;
}
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2023 06:22 AM
@Ankur Bawiskar - Hi, I tested with some users, its not working for the locatio1 users, can you please check once.