scripts to check single line text against table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 07:52 PM - edited 02-14-2024 07:53 PM
I have created Single line text in service catalog, and I have table 'trusted domain whitelisting".
Details as per below
Single line Text variable (u_domain_name)
table name = u_trusted_domain_whitelisting
Table Column 1 = u_active (True/False)
Table Column 2 = u_domain_whitelisting
Here is scenario.
Scenario 1
When user enter a name in u_domain_name (variable), need to validate the domain name is existed or not in table "u_trusted_domain_whitelisting" and check if Table Column 1 = u_active (True) and it should check Table Column 2 = u_domain_whitelisting is existed if yes it need to show up an error message "Domain is available" and when user press "OK" it need to clear the u_domain_name (variable).
Scenario 2
When user enter a name in u_domain_name (variable), need to validate the domain name is existed or not in table "u_trusted_domain_whitelisting" and check if Table Column 1 = u_active (False) and it should skip check Table Column 2 = u_domain_whitelisting and nothing happen.
Please help me any one idea about this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 09:45 PM
Dear Maddysunil,
i have update the client scripts except scripts include and here are the scenario
scenario 1
I have entered u_domain_name (variable) and I receive 2 messages as attach and this domain name "mail.co.za" is part of the list in the table of "u_trusted_domain_whitelisting" and u_domain_name (variable) is cleared which is correct.
scenario 2
I have entered u_domain_name (variable) and I receive 1 message as attach and this domain name "service-now.com" is not part of the list in the table of "u_trusted_domain_whitelisting" and u_domain_name (variable) is not cleared which is correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 09:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 09:59 PM
Dear Maddysunil,
it does not show the actual error messages as attach on my previous chat.
im glad if you can help me further... thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 10:06 PM
To show error message above you replace this line
g_form.showFieldMsg('u_domain_name', "Domain is not available.", 'error');
to below line
g_form.addErrorMessage("Domain is not available");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 10:13 PM
Dear Maddysunil,
can I use back the below client scripts with script included? and remove the checking of u_active is true or false?
function onChange(control, oldValue, newValue, isLoading) {
// Check if the control being changed is 'u_domain_name'
if (control == 'u_domain_name') {
var domainName = g_form.getValue('u_domain_name');
var domainWhitelisting = new GlideRecord('u_trusted_domain_whitelisting');
domainWhitelisting.addQuery('u_domain_whitelisting', domainName);
domainWhitelisting.query();
if (domainWhitelisting.next()) {
// Domain exists in the table
if (domainWhitelisting.u_active) {
// Active domain, show error message
g_form.addErrorMessage("Domain is not available.");
g_form.clearValue('u_domain_name'); // Clear the entered domain
}
// If u_active is false, do nothing
}
// If the domain does not exist in the table, do nothing
}
}