Auto Populate Not Working if Dependent Question Has a Default Value

jmiskey
Kilo Sage

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:

jmiskey_0-1730466149082.png

 

Then, I set up the Requestor Email variable to be Single Line Text, with the Auto Populate tab filled out like this:

jmiskey_0-1730465533382.png

 

And I set up the Requestor Department variable to be a Reference field, with the Auto Populate tab filled out like this:

jmiskey_1-1730465640325.png

 

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.

 

 

1 ACCEPTED SOLUTION

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!

View solution in original post

17 REPLIES 17

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @jmiskey - Your desired behavior is the expected behavior. Are there any client scripts executing onLoad? Are there any errors in the console?

jmiskey
Kilo Sage

No, nothing like that.

 

So it is expected behavior that the Auto Populate fields do NOT populate if the Dependent field is being populated by a Default Value calculation?  What is the logic behind that?  Doesn't seem to make sense to me.

No, when the form is loaded, your three fields Requestor, Requestor Email, Requestor Department should be auto-populated. I assume the disconnect between "Requestor" in your post and "Requestor Name" in your screenshots is a typo.

 

Try setting up a brand new record producer with just those three fields, configured as described, and see if it works.

Yes, sorry that is a typo.  I have named the field "Requestor Name".

 

I have already done what you suggested, which is why I posted this question.  I started with a brand new Record Producer with only these three fields, set-up exactly as I described in my initial post.  When I open the Record Producer on the Service Portal, it shows my name in the "Requestor Name" field, like it should, but the other two fields are blank.  If I changed the "Requestor Name" field at that point to anyone else, it populates those two fields!

 

Did you try it yourself to see if you have this behavior too?