- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- There is a reference variable called Subject Person (points to sys_user).
- If the selected user’s country = India, then at least one attachment must be added before submission.
- If the country is not India, submission should proceed without attachment.
What We Tried So Far:
- OnSubmit Client Script using getReference()
- We fetched the country from the Subject Person record and then checked attachments using Angular DOM (scope.attachments.length).
- Issue: Works partially, but fails when attachments are added (still blocks submission).
- DOM Manipulation Approach
- Used document.getElementsByClassName('get-attachment') for Service Portal and $j("li.attachment_list_items") for native UI.
- GlideAjax + Script Include
- Created a Script Include (CheckAttachment) to check attachments and country.
- Tried multiple patterns (pause submission, resubmit after validation).
- Issue: Logic works for blocking when no attachment, but still blocks even after attachment is added.
- System Property Approach
- Attempted to make country configurable via system property and validate in Script Include.
- Issue: Still facing the same problem with attachment validation.
Where We Are Stuck:
- We need a robust solution that works in Service Portal and Mobile UI.
- Ideally, we want one GlideAjax call that:
- Gets the country.
- Checks if attachments exist for the current record.
- Returns true/false so we can allow or block submission.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
@NowNinja727
I don't know that you can use a scripted method and have it work on both the Service Portal and in Mobile UI. Even if you can pass the necessary info to the Glide Ajax to lookup the attachments the Mobile UI doesn't execute onChange and onLoad client scripts the same way so you would need separate configurations for both.
If you don't want to use a business rule then I think you would need to use an attachment variable on the Record Producer instead of just turning on attachments. Create an Attachment variable on the record producer then use Catalog UI Policy with a UI Policy Action to make it required and visible. This piece would be respected and applied by both the Mobile UI and Service Portal.
In order to do this on both the Service Portal and the Mobile UI you would need to surface the country of the selected Subject Person as a variable in the Record Producer. Once the variable exists you could populate it on the Service Portal side with an onChange script and on the Mobile UI side you would need to use a mobile script or might be able to use a data item lookup. You would then be able to reference the value of this variable in your condition on the Catalog UI Policy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @NowNinja727 ,
I completely understand the pain here , especially when trying to mix onSubmit Client Scripts + attachment checks + server-side country validation. I've faced something very similar recently, and the biggest challenge was exactly what you’re seeing:
-
onSubmit timing issues
-
GlideAjax getXML wait problems
-
attachment DOM logic not syncing fast enough
-
submission blocked even after attaching a file
There are multiple solution patterns available, but if you’re open to a simpler and more reliable approach, I’d strongly suggest using an Attachment variable instead of relying on the default portal attachment panel.
-
You can make the attachment variable mandatory only when Subject Person's country = India
-
Just use an onChange script on Subject Person to evaluate the country, you can use here getReference
-
If country = India → make attachment field mandatory + show any message you want and also you can show this variable only if subject person is from India for other you can keep hidden
This avoids the entire async onSubmit/GlideAjax complexity.
One thing to note:
Attachment variables do NOT automatically attach files to the target record, so add this in your record producer script section:
new global.VariableUtil().copyAttachment(producer.<variableName>, '<tableName>', current.sys_id);
This approach should save you a lot of time and frustration.
🔹 Please mark ✅ Correct if this solves your query, and 👍 Helpful if you found the response valuable.
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@NowNinja727 , I was actually about to share another improvement idea, but while drafting I noticed @John Gilmore already mentioned something similar , and I definitely agree with him.
If you haven’t considered it yet, I think the most efficient direction is:
Create a variable to store Subject Person Country
-
Auto-populate based on Subject Person reference
-
Mark it as hidden, so that it will not show up on the portal.....
Then apply validation using that variable
This gives you a clean and consistent condition to check instead of relying on getReference() timing or any script inlcude or anything
Below is a sample onSubmit script you can adapt to your variable names:
function onSubmit() {
var country = g_form.getValue('subject_person_country');
if (country === 'India') {
var attachmentCount = getSCAttachmentCount(); // Portal attachment count API
if (attachmentCount <= 0) {
g_form.addErrorMessage(
'Please add at least one attachment before submitting this request.'
);
return false;
}
}
}
This should work smoothly, without the async GlideAjax or DOM dependency.
Give it a try and let us know how it goes , if something still blocks, we can troubleshoot further. 🙌
🔹 Please mark ✅ Correct if this solves your query, and 👍 Helpful if you found the response valuable.
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
@Ankur Bawiskar Sure, the boolean in $scope.data.sc_cat_item.mandatory_attachment returned from glidespscriptable to the catalog item widget controls the mandatory asterisk and item submission in the catalog item widget. By manipulating the value in the scope one can make the attachments mandatory like ticking the checkbox in the catalog item record. $scope.$apply is called to trigger an angularjs digest to make sure the view updates but it's not necessary for it to function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @NowNinja727 ,
I completely understand the pain here , especially when trying to mix onSubmit Client Scripts + attachment checks + server-side country validation. I've faced something very similar recently, and the biggest challenge was exactly what you’re seeing:
-
onSubmit timing issues
-
GlideAjax getXML wait problems
-
attachment DOM logic not syncing fast enough
-
submission blocked even after attaching a file
There are multiple solution patterns available, but if you’re open to a simpler and more reliable approach, I’d strongly suggest using an Attachment variable instead of relying on the default portal attachment panel.
-
You can make the attachment variable mandatory only when Subject Person's country = India
-
Just use an onChange script on Subject Person to evaluate the country, you can use here getReference
-
If country = India → make attachment field mandatory + show any message you want and also you can show this variable only if subject person is from India for other you can keep hidden
This avoids the entire async onSubmit/GlideAjax complexity.
One thing to note:
Attachment variables do NOT automatically attach files to the target record, so add this in your record producer script section:
new global.VariableUtil().copyAttachment(producer.<variableName>, '<tableName>', current.sys_id);
This approach should save you a lot of time and frustration.
🔹 Please mark ✅ Correct if this solves your query, and 👍 Helpful if you found the response valuable.
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@NowNinja727 , I was actually about to share another improvement idea, but while drafting I noticed @John Gilmore already mentioned something similar , and I definitely agree with him.
If you haven’t considered it yet, I think the most efficient direction is:
Create a variable to store Subject Person Country
-
Auto-populate based on Subject Person reference
-
Mark it as hidden, so that it will not show up on the portal.....
Then apply validation using that variable
This gives you a clean and consistent condition to check instead of relying on getReference() timing or any script inlcude or anything
Below is a sample onSubmit script you can adapt to your variable names:
function onSubmit() {
var country = g_form.getValue('subject_person_country');
if (country === 'India') {
var attachmentCount = getSCAttachmentCount(); // Portal attachment count API
if (attachmentCount <= 0) {
g_form.addErrorMessage(
'Please add at least one attachment before submitting this request.'
);
return false;
}
}
}
This should work smoothly, without the async GlideAjax or DOM dependency.
Give it a try and let us know how it goes , if something still blocks, we can troubleshoot further. 🙌
🔹 Please mark ✅ Correct if this solves your query, and 👍 Helpful if you found the response valuable.
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @Aniket Chavan , thanks for the reply, 1st one is also good option but we don't wanted to add new Attachment variable and go with the OOB pin icon attachment only, so I'll try as you suggested and let you know, also thanks to @John Gilmore as well for detailed reply.
