The CreatorCon Call for Content is officially open! Get started here.

How can i get a reference field value in ClientScript

kiranped
Giga Contributor

If I create a Request, it will create a Request and RequestItem as child/under of Request and RequestTask created under RequestItem.

here Requester(userfield) and RequestID are fields of Request and is shown on RequestTask form as reference fields.

RequestTask has AssignedTo(Userfield) field.

Now I am writing a client script(on RequestTask) to validate AssignedTo(UserField of RequestTask) can't be same as Requester(userfield which is Request field) which is a reference field on RequestTask

Client Script :

function onSubmit() {

    //Type appropriate comment here, and begin script below

  if(g_form.getValue('requested_for')==g_form.getValue('assigned_to')){           //   alert(g_form.getValue('requested_for')); getting blank , how can i get 'requested_for' field value from RequestTask form

  alert('RequestedFor and AssignedTo can\'t be same');

  return false;

  }else

  {

  return;

  }    

}

Regards,

Kiran Pedduri

1 ACCEPTED SOLUTION

g_form.getDisplayBox('fieldname').value

 

 

 

Mark correct or helpful if it helps you

View solution in original post

19 REPLIES 19

Hi Kiran,



You can access dot-walk fields on a form with the g_form API, without the need of using getReference.



As an example, on the Requested Item [sc_req_item] table there is a derived (or dot-walked) field called Requested for. To get the value you can use:


g_form.getValue("request.requested_for");



"request" is the name of the Request field on the RITM form, and "requested_for" is the field derived from the "request" record.



So the logic you want to work with would be along the lines of:


var requestedFor = g_form.getValue("request.requested_for");


var assignedTo = g_form.getValue("assigned_to");


if (requestedFor == assignedTo) {


      // Do something...


}



This would be useful if the values are expected to change on the form. If the field values are static then you can still use this script, or just follow Christopher's steps and get the dot-walk value in the g_scratchpad variable.



Hope this helps guide your next steps


tried this not working


Thanks Corey


Anurag Tripathi
Mega Patron
Mega Patron

Hey Kiran,



Haven't gone through the whole thread, but to get the value of a reference field on client side you can directly use the code below



g_form.DisplayBox('new_hire_position').value


-Anurag

I tried this in Kingston, but am getting "not a function".  Am I using it wrong?

Here's the code in my onLoad script:

var userID = g_form.getValue("submitter");
console.log('the submitter ref: ' + userID);
var xyz = g_form.DisplayBox('submitter').value;
console.log('###: ' + xyz);
g_form.setValue('attention', xyz);

Here's what comes out to the Console:

the submitter ref: 64fc34064fe3a60072e758211310c743
(g_env) [SCRIPT:EXEC] Error while running Client Script "Set Date and Attention on Order": TypeError: g_form.DisplayBox is not a function