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

johansec
Tera Guru

Is this script being ran on a sc_task? If so I believe that requested for is not a field available on this table. If you want to get the requested for value you must dot walk to its parent request (request).


Is this script being ran on a sc_task? Answer: Yes




Request table Name = sc_request


RequestItem table Name = sc_req_item


RequestTask table Name = sc_task




please let me know the statement. as I have RequestID(REQUEST field) which is reference field on RequestTask form, can I get the Request record object and fetch Requestor field value?


try the following



function onSubmit() {


  var assignedto = g_form.getDisplayValue('assigned_to');


  var requestedfor = g_foem.getDisplayValue('requested_for');




  if ( assignedto == requestedfor )


  {


  Alert('assignedto and requested for can't be same');


  return;


  }



}



Thanks


PS: hit correct/helpful...if it helps


Shishir Srivast
Mega Sage

you can use the getReference to glide the record of particular reference field, please find more details here: GlideForm (g form) - ServiceNow Wiki