- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 01:45 PM
I have tried many times to get this to work. Full disclosure, I know only enough JS to be dangerous.
I am trying to create a catalog item where a user is selected from a lookup select box. The resulting UI policy script should fill in another field with the user ID (user_name). Try as I might, I cannot get this to work the way I expect it to. The field remains blank.
My catalog UI policy script is as follows:
function onCondition() {
u_termed_user.value = u_name.displayValue.user_name;
}
As seen in the pic, despite selecting a user, the user ID field remains blank. What am I doing wrong? Appreciate any help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 02:36 PM
You can do this with a scripted Catalog UI Policy, but best practice is to use UI Policies to set a field/variable as visible, mandatory, and/or read only, or not, and everything else should be done in a Catalog Client Script. Either need to use the same syntax, which at the client level means no dot-walking to get a value from a table based on the value of the field/variable.
If you can change your variable to a reference type, which is more typical when selecting a user, you can create an onChange Catalog Client script that uses getReference to retrieve the user_name field.
If you're going to stick with the lookup select box, then you need to use a GlideAjax call in your onChange Catalog Client Script to a Script Include. This is the best practice anyway, and a good tool to have in your belt. Here is an excellent primer on how to do this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 02:36 PM
You can do this with a scripted Catalog UI Policy, but best practice is to use UI Policies to set a field/variable as visible, mandatory, and/or read only, or not, and everything else should be done in a Catalog Client Script. Either need to use the same syntax, which at the client level means no dot-walking to get a value from a table based on the value of the field/variable.
If you can change your variable to a reference type, which is more typical when selecting a user, you can create an onChange Catalog Client script that uses getReference to retrieve the user_name field.
If you're going to stick with the lookup select box, then you need to use a GlideAjax call in your onChange Catalog Client Script to a Script Include. This is the best practice anyway, and a good tool to have in your belt. Here is an excellent primer on how to do this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 07:09 AM
Thanks Brad. Being perfectly honest, I didn't pay attention to things like scoping and client/server side references. That makes total sense. TBH I am a novice at scripting and immediately blamed myself for bad code rather than an imperfect understanding of the environment I was working in. Given your references, and the state at which I am at on this, I am going to start over from scratch with your advice in mind. Thanks again!