Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Reference Field on Record Producer show Default Value in String field on Task Form?

richelle_pivec
Mega Guru

I am developing a record producer and form for one of our teams. On the record producer, I'd like to use a reference field for the Contact Name, and I have this code in the Default Value field: javascript:getReqfor(gs.getUserID())

It works great to pull the name of the Requested By from the Catalog into the Record Producer. However, the corresponding field on the form is a String field because when it is created directly by someone on our HR team, the person in the Contact Name field might not be someone in our system (a spouse calling about a benefit or something like that). So, I'd like it to use the reference field on the form when an Employee or Contractor uses the record producer on the CMS portal, but I'd like that field to be a string field on the Form itself.  

The Contact Name that is displaying in the reference field on the record producer is populating the corresponding string field on the form with the Sys_ID instead of the Display Value. Any idea on how I can get it to resolve that Sys_ID to the referenced name?

thanks,

Richelle

1 ACCEPTED SOLUTION

paramveer
Mega Guru

instead of write that code in default value of string field, write the same code in script field of "What it will contain" tab of Record producer. Then it should work.



find_real_file.png


Like code written above in script field.



Thanks,


Param


View solution in original post

7 REPLIES 7

paramveer
Mega Guru

Instead of map the value directly like current.string_field = producer.refernce_field_name;



Use below script :



current.string_field = producer.refernce_field_name.getDisplayValue();



Thanks,


Param


I tried it as the default value for the field on the form, and then re-ran the record producer...it did not like that...


current.string_u_contact_name = producer.u_contact_name.getDisplayValue();



Should I set up a "Before" Business Rule?



thanks,



Richelle


paramveer
Mega Guru

Hi Richelle,



That is also an alternative. If we are using before br, then we need to query on table by sys_id and get the display value form there.



Shall I know how you are setting value in string field from reference field.



Thanks,


Param


I created the record producer from the table and then modified the field on the record producer to be a reference field off of the User(sys_user) table. I then added the default value to the field on the record producer that pulls the "Requested For" into the field. On Submit, the record producer sends the sys_id of that "Requested For" person into the corresponding String field on the form.



On Record Producer:


ref.png



On HR Form (with your suggested code in the default value):


hr.png