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

i tried this not working


You question is like a tongue twisters 😉



Please check if this helps.



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


var assign = g_form.getReference('<reference field name of Requester(userfield   of Request table) on RequestTask>', doAlert);


}


function doAlert(assign) {


if (assign.sys_id == g_form.getValue('field name of AssignedTo on RequestTask'))


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


return false;  


}


ccajohnson
Kilo Sage

Since the Requested for field is on the Request [sc_request] table, it may be best to capture that in a g_scratchpad object and check against the Assigned to on the Catalog Task [sc_task] record. In order to set the g_scratchpad object, you need to create an onDisplay Business Rule. Then you will change your script to check accordingly.



1. Create a Business Rule to capture the Requested for Value:


Name: Set g_scratchpad for sc_task


Table: Catalog Task [sc_task]


When: display


Script:


(function executeRule(current, previous /*null when async*/) {


      g_scratchpad.requested_for = current.request_item.request.requested_for;


})(current, previous);



2. Change your onSubmit Client Script:


function onSubmit() {


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


      if (g_scratchpad.requested_for == assignedTo) {


              alert('Requested for and Assigned to can\'t be same');  


              return false;


      }


}


Create an on submit client script like this. Change the alerts as needed.



find_real_file.png


I would avoid doing getReference() calls without a callback function associated with them. Since it appears that there is a hidden field called request, I changed my Business rule accordingly:


(function executeRule(current, previous /*null when async*/) {


      g_scratchpad.requested_for = current.request.requested_for;


})(current, previous);