How to set default value on Reference variable?

Radhika11
Tera Contributor

Hello everyone,

I have two variables (Requested For and Asset Tag).

Based on the user name, asset tag will automatic populate the assets that the user currently have.

 

1.  When the form load, the Asset Tag is showing empty.

Radhika11_0-1691777091276.png

 

2.  When I clicked on the Asset Tag, it showing all the Assets that belonging to the user.

Radhika11_1-1691777641366.png

 

Here is what I would like to accomplish: 

When form load..... 

If user has 1 asset, then default the asset tag in the Asset Tag field

else if user has more then 1 asset, then don't default to the first asset, just list them so that user have an option to select from the dropdown.

 

Thank you so much,

 

 

 

10 REPLIES 10

Hi @SwarnadeepNandy 

I'm still trying to get it to works.  

Here are the steps I have done:

1. Created an OnLoad function in the Catalog Client Scripts

2.  Pasted your suggestion code in the Script Area

3.  Replaced the "requested_for" with "who_is_this_request_for" which is Requested For type name (see below picture)

 

Radhika11_0-1691867183584.png

 

Radhika11_1-1691867629062.png

 

Hi Radhika,


Can you please try like this?

SwarnadeepNan1_0-1691882457488.png

If your requested_for is autopopulating, then use onLoad, if its changing then use on_change client script.

 

Please change the variable name accordingly.

 

Kind Regards,

Swarnadeep Nandy

Hello @SwarnadeepNandy 

Thank you for continuing helping!

1. Currently,  Miranda Hammitt has 1 asset in her possession.

 

Radhika11_1-1691904181552.png

 

2. Login as Miranda, the Asset Tag is showing blank. Since she has only 1 asset, it should populate that asset number in the Asset Tag field.

 

Radhika11_2-1691904729304.png

 

3. Here is the entire code.  Did I made a typo somewhere in the code?

Radhika11_3-1691905057914.png

 

 

 

 

Hello,

Try putting console.log() statements to debug the code.

Maybe change the onLoad to onChange - field (who is this request for).

 

Kind Regards,

Swarnadeep Nandy

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

You can simpy pass below qualifier on the Asset Tag field as below.

javascript: 'assigend_to='+current.variables.who_the_request_is_for;

Replace who_the_request_is_for with the variable name where you select the user name.