compare two variables on on a catalog item

dilini
Giga Expert

I'm trying to compare two variables on on a catalog item. One variable is text type variable and the other one is reference type variable. Please see below: Requestor and the Approver should be the same person.   I tried below onChange scrip. That doesn't work.

Screen Shot 2016-12-15 at 2.19.17 PM.png

Screen Shot 2016-12-15 at 2.20.44 PM.png

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

              if (isLoading || newValue == '') {

      return;

  }

  if (g_form.getValue('infoblox_host_req_txtbox_requestor_name').toString() == g_form.getValue('infoblox_host_req__ref_approver').toString()) {

alert("The requstor and the approver cannot be the same person");

  }

  }

5 REPLIES 5

randrews
Tera Guru

g_form.getValue('infoblox_host_req__ref_approver').toString())



should return the SID For the approver.. not the display value.. try replacing the .toString with .getDisplayValue()... or both   .getDisplayValue().toString()


HV1
Mega Guru

Comparing names is not an ideal comparison, as it can be same for different userIDs.   Why are you not using Requestor's name as a reference field too?



As in for your script, try using getDisplayValue for your reference field.


g_form.getDisplayValue('infoblox_host_req__ref_approver').toString()


Sorry should have said that also.. i can't emphasize how much i agree.. never do a check like this with a user entry if you can avoid it... this is a really bad idea...



if the user types in Bob Tilton.. and the ref field is Robert Tilton your comparison will have no issue with that .... good catch


BALAJI40
Mega Sage

Use this script,



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


              if (isLoading || newValue == '') {


      return;


  }


  if (g_form.getValue('infoblox_host_req_txtbox_requestor_name') == g_form.getReference('infoblox_host_req__ref_approver').name) {


alert("The requstor and the approver cannot be the same person");


  }


  }