- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 12:16 PM
I have a catalog item that I'm trying to restrict users from submitting if the request is for themselves. In my client script I am comparing 2 fields. If the name is the same in both fields, the alert is triggered referring them to their manager. That piece seems to be working. If the 2 fields are different, they should be able to continue with the request. But when the 2 fields are different the alert is still being triggered. I'm fairly new when it comes to JavaScript, any help/suggestions would be appreciated. I have attached my script. Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 11:03 AM
So you are seeing the alert window (for the variable value), but it is empty, or does it say 'undefined' or 'null'? Have you confirmed that these are exactly the names of the variables - case-sensitive and no trailing space or anything like that? Since this is onChange, you can use newValue for the request_access script variable, or in the if condition. It would be super weird if you alert on newValue and it is empty, after having selected a user in the reference field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 03:32 PM
Hi Kathi,
Can you confirm if the requested_for and requested_access_for are both reference (or Requested For) type variables? Add an alert prior to the if statement, so that you know what the script is seeing as the two variables in the if statement. I'm not sure what the last line with parent.document is trying to do, so maybe comment that out in case it's affecting the script, otherwise it looks pretty straightforward. This script is running onChange of which variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 10:30 AM
Both the requested_for and request_access are reference types. The script is running on change to the request_access field. The last line (parent.document) just kicks the user back out to the portal when they click "OK". I have commented that line out for testing. I added the alert but it isn't grabbing the variable value. I tried both defined variables, same result.
var cur_user = g_form.getValue('requested_for');
var request_access = g_form.getValue('requesting_access_for');
alert(request_access);
if (request_access == cur_user); {
g_form.setValue('requesting_access_for', '');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 11:03 AM
So you are seeing the alert window (for the variable value), but it is empty, or does it say 'undefined' or 'null'? Have you confirmed that these are exactly the names of the variables - case-sensitive and no trailing space or anything like that? Since this is onChange, you can use newValue for the request_access script variable, or in the if condition. It would be super weird if you alert on newValue and it is empty, after having selected a user in the reference field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 01:04 PM
I found an upper case where there should have been a lower case. Thank you.