- 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 11:00 AM
I can confirm that auto-populate works as expected without any catalog client script, even as an order guide.
While I think it is important to understand why it's not working, I do wonder about the validity of the requirement. You mention the Email and Department fields will be read only...why even show them to the user? What are you doing with the email/department values that you can't accomplish "behind the scenes"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 12:04 PM
These Record Producers are creating SAFe Epic records, and all the values from those fields are being scripted and written to the HTML Description field of this record (and these records are being sent over to Azure DevOps through integration).
You are correct, in that these field values probably do not need to be displayed on the selection form to the user. They are just there because they are being passed over to the record being created, but they probably do not really need to be visible on the Service Portal.
This is the code that is used in the Record Producer to write all these variables to the SAFe Epic that gets created:
(this is just a small subset - it if obviously much larger than this, with a lot more fields).
I suppose I could do the calculations in here. Though now we are getting away from the real purpose of my question - to determine if Auto Populate can be used in this manner or not. Whether we are doing something wrong, or it just isn't possible in this scenario.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 09:26 AM
Hi @jmiskey ,
you can write onliad client script to set the value.
make ajax call to call script include to get the login user details .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 09:45 AM
That is not necessary. You can use the code that I show above to do it with a getReference call instead of a GlideAjax. Also, by commenting the "default" three lines that it gives you for OnChange scripts, this will work for BOTH OnChange and OnLoad (in one single script!).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 09:56 AM - edited 11-01-2024 10:21 AM
Hi @jmiskey,
Out of interest, just as you've set the default value for the Requestor field, what has been set or implemented for the Email and Department field default values?
Testing this on my PDI - by simply setting the default value of the Requestor, the Email field using the 'Auto populate' as you've configured works as expected with no default value set.... this is however on a catlog item - not a record producer (so that would need confirming)
If you wanted to set the default values, you can leverage a very similar script and method as the 'javascript:gs.getUser()' call.
For email, use javascript:gs.getUser().getEmail() and for department use javascript:gs.getUser().getDepartmentID()
Set the default values using the appropriate syntax (as above) for each field and that should provide you with what you're looking for.
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