- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 05:17 AM
Hello!
We have a Catalog Client Script that checks onSubmit if any of 3 checkboxes are selected on the form of a RITM and forces the user to attach a file on the ticket.
The script works as intended on the creation of the request but when the fulfiller tries to assign the ticket to an agent, she/he receives and error on Save/Update.
Error MessageonSubmit script error: TypeError: this is null:
function() {
[native code]
}
We are unable to assign the ticket as long as it has an attachment.
The script is
function onSubmit() {
var cM = g_form.getValue('card_modification');
var tD = g_form.getValue('transaction_dispute');
var cLM = g_form.getValue('card_limit_monitoring_increase');
if (cM == 'true' || tD == 'true' || cLM == 'true') {
if (this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage(getMessage('Please, add an attachment file.'));
return false;
}
}
}
Is there anything we can do to correct the issue?
Thank you in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 06:57 AM
Please try with below updated code:
function onSubmit() {
var cM = g_form.getValue('card_modification');
var tD = g_form.getValue('transaction_dispute');
var cLM = g_form.getValue('card_limit_monitoring_increase');
if (cM == 'true' || tD == 'true' || cLM == 'true') {
var attachmentField = g_form.getControl('attachment'); // Assuming the attachment field is named 'attachment'
var attachments = attachmentField.getAttachmentList();
if (attachments.length == 0) {
g_form.addErrorMessage('Please, add an attachment file.');
return false;
}
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 05:52 AM
The issue you're experiencing is due to the fact that the client script is running for all users, including fulfillers, and it's checking for attachments every time the form is submitted. This is causing an error when fulfillers try to assign the ticket because the script is still expecting an attachment.
Here's how you can resolve this issue:
1. Add a condition to check if the user is a fulfiller before running the attachment check. You can use the g_user object to get the current user's roles and check if they have the 'fulfiller' role.
2. Modify the script to only run the attachment check when the form is being submitted for the first time. You can do this by checking if the sys_id of the record is empty, which would indicate that it's a new record.
Here's a sample code:
javascript
function onSubmit() {
var cM = g_form.getValue('card_modification');
var tD = g_form.getValue('transaction_dispute');
var cLM = g_form.getValue('card_limit_monitoring_increase');
// Check if the user is a fulfiller
var isFulfiller = g_user.hasRole('fulfiller');
// Check if the form is being submitted for the first time
var isNewRecord = g_form.getValue('sys_id') == '';
if ((cM == 'true' || tD == 'true' || cLM == 'true') && !isFulfiller && isNewRecord) {
if (this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage(getMessage('Please, add an attachment file.'));
return false;
}
}
}
This script will only run the attachment check when the form is being submitted for the first time and the user is not a fulfiller. This should resolve the issue you're experiencing.
nowKB.com
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/
For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 06:31 AM
@Stergios Stergi in onSubmit script, you can check the user role to distinguish between a user who initially creates the RITM and a fulfiller. This way the attachment would be no longer necessary for the fulfiller who is reassigning the ticket.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 06:57 AM
Please try with below updated code:
function onSubmit() {
var cM = g_form.getValue('card_modification');
var tD = g_form.getValue('transaction_dispute');
var cLM = g_form.getValue('card_limit_monitoring_increase');
if (cM == 'true' || tD == 'true' || cLM == 'true') {
var attachmentField = g_form.getControl('attachment'); // Assuming the attachment field is named 'attachment'
var attachments = attachmentField.getAttachmentList();
if (attachments.length == 0) {
g_form.addErrorMessage('Please, add an attachment file.');
return false;
}
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 10:20 PM
Hello Maddy!
It seems that your proposal worked like a charm!
Thank you very much!!