- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 05:58 AM - edited 11-01-2024 06:02 AM
I am creating a Record Producer (though I suspect the same would be true for a Catalog Item) where I have three fields at the beginning:
- Requestor
- Requestor Email
- Requestor Department
These should all be auto-populated when the Record Producer is opened on the Service Portal to be filled out.
For the Requestor field, I have a default value of:
Then, I set up the Requestor Email variable to be Single Line Text, with the Auto Populate tab filled out like this:
And I set up the Requestor Department variable to be a Reference field, with the Auto Populate tab filled out like this:
The goal is when you open the form from the Service Portal, all three of these fields will be automatically populated (I ultimately want to make them all Read-Only so the Requestor cannot change their values).
The issues is when you open up the form, it populates the Requestor with the correct value, but does not pre-populate the other two fields. It only populates them if you change the Requestor value (so it does not appear that this "Auto Populate" feature works "On Load" - it behaves more like "On Change" of the Dependent field).
Is there an easy way to get these fields to behave properly, and all 3 automatically populate when the form loads, without having to go back to the old method of using Catalog Client Scripts?
This auto-populate seems like a nice feature, if we could get it to work properly!
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 08:31 AM - edited 11-01-2024 08:32 AM
Figuring it might be the Order Guide (as I know that has a lot of limitations), I removed the Auto Populate features for those two fields, and created a Catalog Client Script that runs On Change of my "Requested Name" field that has a callback function that looks like this:
function onChange(control, oldValue, newValue, isLoading) {
// if (isLoading || newValue == '') {
// return;
// }
var req_for = g_form.getReference('requestor_name', setUserFields);
function setUserFields(req_for){
g_form.setValue('requestor_email',req_for.email);
g_form.setValue('requestor_department',req_for.department);
}
}
This works as expected, so I think I will just go with this option.
Thanks for looking into it though!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 10:05 AM
We kind of went back-and-forth on whether or not to lock down the "Requestor Name" field. Most of the time, the person will be submitting it for themselves. But it has been determined that there may be some rare exceptions in which they could be submitting it for someone.
So, since we would need the Email address and Department to change if the Requestor Name field is changed, using the Default values for the other two fields is not really a good option.
I have marked my post as the solution, as we got a working solution on this that works well. I was just excited about the possibility of using this newer Auto Populate option, and was trying to figure out why it did not work in this case. My best guess is, like other things, it just does not work in Order Guides.
So just to be clear, I was not looking for alternative solutions - I was just curious as to why this Auto Populate feature does not work in this scenario. No further replies are really needed unless someone can provide a definitive explanation of why Auto Populate does not work in this scenario.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 10:27 AM - edited 11-04-2024 12:52 AM
Hi @jmiskey,
As you'll see from my initial post, I tested this via a catalog item, but I would need to verify against a Record Producer - let me confirm that.
Just an important point to note, whilst this is working via the client script, you should know that as per ServiceNow best practices is not recommended to use the g_form.getReference() method (even with a callback) due to their performance impact. The method retrieves all fields in the requested GlideRecord object when most cases only require one field.
For ultimate performance, you want to use an Ajax call.
ServiceNow best practice link: https://developer.servicenow.com/dev.do#!/guides/xanadu/now-platform/tpb-guide/client_scripting_tech...
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 10:36 AM
It is not enough to test just a Record Producer, it also needs to be in an Order Guide as well. I think that may be the crux of the issue.