Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2025 12:12 AM
Hi,
Could you please advise is this possible to consolidate both function 'val_otherconttypes' and 'val_ContType'.
I have tried to merge both function but it didnt work. please advise. Thanks.
function checkifnotuser(locationId) {
var msg = '';
if (!val_ContType(locationId, 'Primary Site', ['User'])) {
msg += 'Primary Site must be user.'+'\n'; }
if (!val_ContType(locationId, 'Secondary Site', ['User'])) {
msg += 'Secondary Site must be user.'+'\n';} }
function checkother(locationId) {
var msg = '';
if (!val_otherconttypes(locationId, 'Primary NW', ['Other'])) {
msg += 'Primary NW must be user or group.'+'\n';
}
if (!val_otherconttypes(locationId, 'Secondary NW', ['Other'])) {
msg += 'Secondary NW must be user or group.'+'\n';
}
}
function val_otherconttypes(locationId, contactType, allowedTypes) {
var gr = new GlideRecord('u_location_contact');
gr.addQuery('u_location', locationId);
gr.addQuery('u_contact_type', contactType);
gr.query();
while (gr.next()) {
var typeValue = gr.getValue('u_group_user');
if (allowedTypes.includes(typeValue)) {
return false;
}
}
return true;
}
function val_ContType(locationId, contactType, allowedTypes) {
var gr = new GlideRecord('u_location_contact');
gr.addQuery('u_location', locationId);
gr.addQuery('u_contact_type', contactType);
gr.query();
while (gr.next()) {
var typeValue = gr.getValue('u_group_user');
if (!allowedTypes.includes(typeValue)) {
return false;
}
}
return true;
}
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2025 01:57 AM
Hi @BanuMahalakshmi
Try the below function. It'll work.
function val_ContType(locationId, contactType, allowedTypes) {
var type = allowedTypes[0];
var gr = new GlideRecord('u_location_contact');
gr.addQuery('u_location', locationId);
gr.addQuery('u_contact_type', contactType);
gr.query();
while (gr.next()) {
var typeValue = gr.getValue('u_group_user');
if (type == 'User') {
if (allowedTypes.includes(typeValue)) {
return false;
}
}
if (type == 'Other') {
if (!allowedTypes.includes(typeValue)) {
return false;
}
}
}
return true;
}
Regards,
Siva
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2025 01:57 AM
Hi @BanuMahalakshmi
Try the below function. It'll work.
function val_ContType(locationId, contactType, allowedTypes) {
var type = allowedTypes[0];
var gr = new GlideRecord('u_location_contact');
gr.addQuery('u_location', locationId);
gr.addQuery('u_contact_type', contactType);
gr.query();
while (gr.next()) {
var typeValue = gr.getValue('u_group_user');
if (type == 'User') {
if (allowedTypes.includes(typeValue)) {
return false;
}
}
if (type == 'Other') {
if (!allowedTypes.includes(typeValue)) {
return false;
}
}
}
return true;
}
Regards,
Siva