- 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 08:11 AM
Hi @Mayur2109 ,
I made the updates that you provided and it's still not working. I really appreciate your help. Let me know if you have any other ideas
So here is my client script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 08:18 AM
Hi @SandyL83 ,
Can you please change function name at both script include, client script & make it same, I'm seeing it as ga.addParam("sysparm_name", "function") in client script and in script include function_name: function() .
Let me know if you still face issue.
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-22-2023 07:08 AM
Hi @Mayur2109 - thanks so much..
Here is my updated script includes: (notice I changed the function name to checkData). it still doesn't seem to be working even though I think I am calling it correctly. Any ideas? Thanks again for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2023 07:19 AM
Hi @SandyL83 ,
Put logs and check if you are getting correct value in script include for param then check if query is returning anything or not in if loop of script include, then check if answer contains any value in client script.
Regards,
Mayur Shardul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 07:05 AM
update your script as this
Script Include: It should be client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkData: function(){
var name = this.getParameter('sysparm_company');
var gr = new GlideRecord('core_company');
if(gr.get('name', name)){
return true;
}
return false;
},
type: 'checkRecords'
});
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('vendor'); // give here field/variable name
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkData");
ga.addParam('sysparm_company', g_form.getValue('vendor')); // give here field/variable name
ga.getXMLAnswer(function(answer){
if(answer.toString() == 'false'){
var message = 'This hardware is not present';
g_form.clearValue('vendor'); // give here field/variable name
g_form.showFieldMsg('vendor',message,'error', true);
}
});
//Type appropriate comment here, and begin script below
}
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