Need help with making 2 variables on a catalog item confirm the info entered is not already existing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2023 11:33 AM
I need 2 variables that are in a variable set to check if information entered already exists and to provide an error message and hard stop if they do already exist. It is a first_name and last_name variable.
So what is happening currently if a user says they want to add the information Paddy Omally and submit it and someone else does the exact same thing, both are being created, there is no check to see if that information already exists. This information is forward to a fulfiller who will create a user based on that information so these fields are not currently writing to the sys_user table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2023 12:53 PM
Hi Genna!
It sounds like an onSubmit Catalog Client Script should do the trick. If you are using Service Portal / Employee Center/... as opposed to the native Service Catalog UI you'll want to do this with 2 of the same scripts onChange of the last_name and first_name variables, because the Service Portal asynchronous structure does not allow the submit to be aborted, and leave it up to users to complete/update the variables out of order. In any event you need to use a GlideAjax call to a Script Include. Here is an excellent guide if you're not familiar with how to do this:
This goes a bit beyond what you need as it shows how to return more than one value, and in your case you'll just be returning a 'true' or 'false' or whatever with a return false; if it exists - or in an onChange script, clear one or both of the mandatory variables so that the request cannot be submitted. Your SI will do a GlideRecord query on the user table checking the first_name and last_name values passed in from the client script, and return one value if a (active?) record is found, or a different value if it is not found, then the callback function in the Client Script will evaluate that returned value to determine how to proceed. Give the scripts a shot, and let me know if you get stuck. Of course 2 people could submit a request with the same names and you would still wind up with duplicates if the first request is not fulfilled before the second one is created. You could also add a Business rule to the sys_user table to prevent a record from being added with the same first and last name fields as an existing (active) record, then the fulfiller would reject the second request in this event. Happy coding!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2023 01:58 PM
I have bare minumum scripting knowledge when it comes to this stuff and although you sent the link I dont have a keen understanding of it as of yet. Can I get further help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2023 02:18 PM
I have come up with this:
I need to do it for last_name too though and I am not sure if this is even correct