Pls let me know the issue in the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2025 12:51 AM
Hi
Please let me know the correction in the script, this script executes fine except the scenario - this script prints the value "Local Support type must be user group." still though there is no record exist in the Point of contact table for the relevant location . please advise the suggestion in the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2025 01:10 AM
Hi @BanuMahalakshmi
Not sure about requirement, one observation in checkifnotgroupContTypes method
you missed this keyword while calling validateConactType Method in if statement.
checkifnotgroupContTypes: function(locationId) {
var msg = '';
if (this.validateContactType(locationId, 'Local Support', ['Group'])) {
msg += 'Local Support type must be group.' + '\n';
}
return msg;
}, Note: this keyword refers to the object that is currently executing the code. Make sure to add this when we calling methods which are existing in same script include.
If this helped to answer your query, please mark it helpful & accept the solution.
Thanks!
Krishnamohan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2025 01:11 AM
changes below
1) you should use this operator to call the method, you were missing that
2) update this method validateContactType
validateContactType: function(locationId, contactType, allowedTypes) {
var gr = new GlideRecord('u_location_point_of_contact');
gr.addQuery('u_location', locationId);
gr.addQuery('u_contact_type', contactType);
gr.addQuery('u_active', true);
gr.query();
var recordExists = false;
while(gr.next()) {
recordExists = true;
var typeValue = gr.getValue('u_group_user'); // 'User', 'Group', etc.
if (!allowedTypes.includes(typeValue)) {
return false; // Invalid type found
}
}
return recordExists ? true : true; // If no records, treat as valid (no error)
},
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
‎09-08-2025 11:28 AM
Thanks for reply, i tried recordExist but it didnt works. 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2025 01:50 AM
The problem is in your function checkifnotgroupContTypes.
Right now you have:
checkifnotgroupContTypes: function(locationId) {
var msg = '';
if (validateContactType(locationId, 'Local Support', ['Group'])) {
msg += 'Local Support type must be group.' + '\n';
}
return msg;
},
Issues:
- You forgot the this. prefix → It should be this.validateContactType(...), not just validateContactType(...).
Without this., it is calling nothing (or global scope), and behaves unexpectedly. - Your validation logic is inverted
Right now, you are adding the error message if validation passes.
But the intention is to add the error message if the validation fails (same as your other checks).
Corrections:
checkifnotgroupContTypes: function(locationId) {
var msg = '';
if (!this.validateContactType(locationId, 'Local Support', ['Group'])) {
msg += 'Local Support type must be group.' + '\n';
}
return msg;
},
