Prepopulate Reference Field

chriscorbett
Giga Contributor

Hello All --

I know this is possible but I'm drawing a complete blank. I'm trying to establish a reference field link between two tables so that data from one

table can be displayed on the other. I'm trying to configure it so that the reference field is populating on its own without needing to manually

type anything in.

Here's my set up

2016-08-22_12-54-35.png

Number is my autonumbered record. Approval History is a reference to a second table where I store the Number plus the fields I have showing under the green arrow.

The structure of that table is like this:

2016-08-22_13-06-00.png

I am trying to populate the Approval History field to prepopulate so the field information shows on its own.

I have tried both a client script and business rule to populate the field with no luck. In both cases, I used code like this:

var id = current.sys_id;

current.u_approval_history = id;

current.update();

To no avail.

I would appreciate other ideas on how to do this.

Thanks!

Chris

6 REPLIES 6

galavodasal
Giga Expert

I think you're just missing the .getDisplayValue() .


Alexander -



I'm not sure where the getDisplayValue would go in this case - could you be more specific?


Sorry, I read the tail end of your message and might not even be addressing the main issue. I actually just tested it out with a client script and I didn't need to add getDisplayValue()



I made a client script that reads the user in one reference field and grabs their location and enters it in the 'district' field, which is a reference field to our cmn_location table.



function onChange(control, oldValue, newValue, isLoading) {


      if(isLoading){ return; }


      var userRecord = g_form.getReference('requested_for');


      g_form.setValue('district', userRecord.location);



}                            


I tried the following in an onLoad client script and I still get nothing:



function onLoad() {


   


      var approvalHist = g_form.getReference('u_approval_history');


      g_form.setValue('u_approval_history', approvalHist.u_request_id);




}