- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 05:33 AM
Hello,
I have a RITM that is related to vendor risk managment .. this ritm sets up a vendor on the core_company table.
On the RITM form, there is the a reference field that allows user to select vendor; and if the vendor is not already on the core_company table, we have a checkbox that says "vendor not found". If that is checked, the user enters the Vendor name in a free form text field and then the vendor record is created on the core_company table. The problem is, people aren't checking the reference field to see if the vendor exists, they are usign the free form field. so, many duplicate vendors are being created.
Does anyone have any ideas on how to write a script to prevent this - ideally if someone types in "VEndor A" in the free form, i'd like a message that says "Vendor A already exits, please select that from the field above".
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 07:54 AM
Hi @Ankur Bawiskar and @Mayur2109 ,
Thanks for all of the valuable feedback. Turns out all I needed was the following client script - no script includes was required:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 05:42 AM
Hi @SandyL83 ,
You can write a onChange client script for this and pass the value entered by user to a client callable script include.
From script include you can query core_company table and check if vendor is present. If the vendor is there pass answer as false to client script and add info message "Vendor A already exits, please select that from the field above".
Please check and Mark Helpful and Correct if it really helps you.
Regards,
Mayur Shardul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 06:36 AM
Hi @Mayur2109
Thanks for the response. Here is what I have so far based on your feedback and it still doesn't seem to be working.. any other suggestions? thanks again
1. here is my script includes:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 06:49 AM
Hi @SandyL83 ,
Your script include doesn't seems to be client callable, please check it again and check outputs by putting logs.
Regards,
Mayur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 07:00 AM - edited ‎09-21-2023 07:07 AM
Hi @SandyL83 ,
Try below changes it will work.
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("script_include_name");
ga.addParam("sysparm_name", "function_name");
ga.addParam("sysparm_var", newValue);
ga.getXML(callBackFunction);
function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
g_form.addInfoMessage('Duplicate Message');
g_form.clearValue("field_name")
}
}
}
Script Include: Make sure it is client callable.
function_name: function() {
var param = this.getParameter("sysparm_var");
var gr = new GlideRecord("table_name");
gr.addQuery("field_name", param);
gr.query();
if (gr.next()) {
return true;
}
},
Please check and Mark Helpful and Correct if it really helps you.
Regards,
Mayur Shardul