Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Setting a field value on load

Cirrus
Kilo Sage

Can anyone advise on what I thought would be a simple configuration.

We have developed a custom form, and one of the fields pulls in the parent reference (in this case the parent project number) when we load a new record. No issues there.

We have another field on the form which is also a reference to the project table. We are trying to populate that field on load with the same parent project value. If I populate it manually I can see that both sys_ids match, but when I run an on load client script to set the value, it fails, even though it is passing the sys_id value of the parent. The script is as follows:

 

function onLoad() {
  var gr = g_form.getValue('parent');
  alert("Value + " + gr);//is getting the sys_id of the parent project on load
  g_form.setValue('u_provided_to', gr);
  }
 

By the way, we have a genuine reason for wanting to reference the same record twice. 

 

1 ACCEPTED SOLUTION

Robbie
Kilo Patron

Hi @Cirrus,

 

This should be easily achieved assuming both fields are reference field that point to the same underlying table.

Use the following syntax in your script and adjust accordingly:

(Additionally, make sure your Client Script 'UI Type' field is set to All)

 

 

 

function onLoad() {
   var sourceField = g_form.getValue('parent');
   if(sourceField){
	g_form.setValue('u_provided_to', sourceField);
   }
}

 

 

Best practice tip - avoid at all times variables with the name 'gr' (A common used variable when calling GlideRecord - this should be avoided at all times)

 

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

View solution in original post

3 REPLIES 3

Anurag Tripathi
Mega Patron

Hi,

Try this

function onLoad() {
  var gr = g_form.getDisplayBox('parent').value
  alert("Value + " + gr);//using dispay valyue instead of sys_id
  g_form.setValue('u_provided_to', gr);
  }
-Anurag

Robbie
Kilo Patron

Hi @Cirrus,

 

This should be easily achieved assuming both fields are reference field that point to the same underlying table.

Use the following syntax in your script and adjust accordingly:

(Additionally, make sure your Client Script 'UI Type' field is set to All)

 

 

 

function onLoad() {
   var sourceField = g_form.getValue('parent');
   if(sourceField){
	g_form.setValue('u_provided_to', sourceField);
   }
}

 

 

Best practice tip - avoid at all times variables with the name 'gr' (A common used variable when calling GlideRecord - this should be avoided at all times)

 

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

Thanks Robbie. Did exactly what it needed to to prove the concept and now working as part of an on change script to deliver the requirement