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

Clear/Set value of g:ui_reference field in ui page

gowthamanbalu
Tera Contributor

Hi Guys,

        In the below UI page,

                        1. I want a function wherein, if shared check box is enabled, Assigned to reference field should be cleared. I tried with the below client script, the value of assigned to field is changing to null but the same is not reflecting in the UI form.

                        2. If assignee is populated, based on assignee filed value, cost center field should auto populated. Here also, cost center value is changing and i can see the value when I give alert but the same is not reflecting in the UI form.

UI Page:

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

  <g:ui_form>

  <style>

li {

  display:inline;

  padding: 5px;

}

  </style>

  <header>

  <h3 style="color:blue;">ASSIGN ASSET FROM STOCK</h3>

  </header><hr></hr>

  <table>

  <tr id="dialogbuttons">

  <td>

  <label for="${jvar_ci_query}" onclick="" dir="">${gs.getMessage('In Stock Asset to be Assigned')}

  <span class="required">*</span></label>

  </td>

  <td>

  <g:ui_reference id="assetToBeReturned" name="QUERY:u_asset_state!=1^assigned_toISEMPTY^u_is_shared=false" table="alm_asset"/>

  </td></tr>

<tr id="dialogbuttons">

<td>

  <label for="${jvar_ci_query}" name="assignto" id="assignto" onclick="" dir="">${gs.getMessage('Assign to')}

  <span class="required">*</span></label>

  </td>

  <td><div id="assigndiv">

  <g:ui_reference name="assignedto" id="assignedto" table="sys_user" onchange="clrasgn();"/>

  </div></td></tr>

  <tr id="dialogbuttons">

<td>

  <label for="${jvar_ci_query}" onclick="" dir="">${gs.getMessage('Cost Center')}

  <span class="required">*</span></label>

  </td>

  <td>

  <g:ui_reference name="costcenter" id="costcenter" table="cmn_cost_center"/>

  </td></tr>

  <tr id="dialogbuttons">

<td>

  <label for="${jvar_ci_query}" onclick="" dir="">${gs.getMessage('Location ')}

  <span class="required">*</span></label>

  </td>

  <td>

  <g:ui_reference name="location" id="location" table="cmn_location"/>

  </td></tr>

  <tr id="dialogbuttons">

<td>

  <label for="${jvar_ci_query}" onclick="" dir="">${gs.getMessage('Shared')}

  <span class="required">*</span></label>

  </td>

  <td>

  <input type="checkbox" name="shared" id="shared" onclick="shardType();" />

  </td></tr>

  <tr id="dialogbuttons">

<td>

  <label for="my_choice" id="my_choice" style="display: none">Shared Type

  <span class="required">*</span></label>

  <select name="my_substate" id="my_substate" onclick="optionSelect();" style="display:none">

  <option selected = "selected">--None--</option>

              <option> Branch </option>

  <option> Call Center </option>

  <option> Workstation Scanner </option>

  <option> Other </option>

</select>

  </td></tr>

  <tr id="dialogbuttons">

<td>

  <label for="${jvar_ci_query}" name="brachname" id="brachname" onclick="" dir="" style="display: none">${gs.getMessage('Branch')}

  <span class="required">*</span></label>

  </td>

  <td><div id="branchdiv" style ="display: none">

  <g:ui_reference name="branch" table="u_extra_location" />

  </div></td></tr>

  <tr id="dialogbuttons">

<td>

  <label for="${jvar_ci_query}" id="cubelab" onclick="" dir="" style="display: none">${gs.getMessage('Cube Number')}

  <span class="required">*</span></label>

  </td>

  <td>

  <input type="text" name="cube" id="cube" style="display: none"/>

  </td></tr>

  <tr id="dialogbuttons">

<td>

  <label for="${jvar_ci_query}" id="otherlab" onclick="" dir="" style="display: none">${gs.getMessage('Other')}

  <span class="required">*</span></label>

  </td>

  <td>

  <input type="text" name="other" id="other" style="display: none"/>

  </td></tr>

<td>

  <g2:dialog_button onclick="return onSubmit();" name="assignasset" id="assignasset">${gs.getMessage('Assign Asset')}</g2:dialog_button>

  </td>

  </table>

  </g:ui_form>

</j:jelly>

Client Script:

function clrasgn(){

shardType();

}

function shardType(){

  var sh= document.getElementById("shared").checked;

  if (sh == true){

  //var temp = '';

  //document.getElementsByName("assignedto").style.visibility = "hidden";

  document.getElementById("my_substate").style.display = "block";

  document.getElementById("my_choice").style.display = "block";

  document.getElementById("my_substate").value = "--None--";

  //alert(gel('assignedto').value);

  //document.getElementById("assignedto").value="";

  //document.getElementById("assigndiv").style.display = "none";

  //document.getElementById("assignto").style.display = "none";

  //document.getElementById("assignedto").innerHTML = temp;

  gel('assignedto').value="";

  alert(gel('assignedto').value);

  //function checkShrd(){

  //var asn = gel('assignedto').value;

  // alert(asn);

  //if (asn != ''){

  //alert('test');

  //var temp='';

  //gel('assignedto').value= temp;

  //var query= gel('assignedto').value;

  //alert(query);

  //return query;

  //}

  //return null;

  //alert(asn);

  //document.getElementById("assignedto").value="";

  //g:ui_reference.setdisplayalue('assignedto','');

  //alert(gel('assignedto').value);

  }

  //asn.value="";

  //alert(gel('assignedto').value);

  //return asn.value;

  else if (sh == false){

  document.getElementById("my_substate").style.display = "none";

  document.getElementById("my_choice").style.display = "none";

  document.getElementById("assigndiv").style.display = "block";

  document.getElementById("assignto").style.display = "block";

  //document.getElementById("assignedto").style.visibility = "visible";

  document.getElementById("brachname").style.display = "none";

  document.getElementById("branchdiv").style.display = "none";

  document.getElementById("cube").style.display = "none";

  document.getElementById("cubelab").style.display = "none";

  document.getElementById("other").style.display = "none";

  document.getElementById("otherlab").style.display = "none";

  }

}

var sh= document.getElementById("shared").checked;

document.getElementsByName('my_substate').onchange = function() {

  if (this.value=='--None--') {

  alert('Please Select Shared Type !');

  document.getElementById("brachname").style.display = "none";

  document.getElementById("branchdiv").style.display = "none";

  document.getElementById("cube").style.display = "none";

  document.getElementById("cubelab").style.display = "none";

  document.getElementById("other").style.display = "none";

  document.getElementById("otherlab").style.display = "none";

  }

  if (this.value == 'Branch' &&   this.value !='Call Center' && this.value !='Workstation Scanner' && this.value!='Other' ) {

  document.getElementById("brachname").style.display = "block";

  document.getElementById("branchdiv").style.display = "block";

  document.getElementById("cube").style.display = "none";

  document.getElementById("cubelab").style.display = "none";

  document.getElementById("other").style.display = "none";

  document.getElementById("otherlab").style.display = "none";

  }

  if ((this.value == 'Call Center' ||   this.value == 'Workstation Scanner') && this.value != 'Branch' && this.value != 'Other') {

  document.getElementById("brachname").style.display = "none";

  document.getElementById("branchdiv").style.display = "none";

  document.getElementById("cube").style.display = "block";

  document.getElementById("cubelab").style.display = "block";

  document.getElementById("other").style.display = "none";

  document.getElementById("otherlab").style.display = "none";

  }

  if (this.value == 'Other' && this.value !='Call Center' && this.value !='Workstation Scanner' && this.value!='Branch' ) {

  document.getElementById("brachname").style.display = "none";

  document.getElementById("branchdiv").style.display = "none";

  document.getElementById("cube").style.display = "none";

  document.getElementById("cubelab").style.display = "none";

  document.getElementById("other").style.display = "block";

  document.getElementById("otherlab").style.display = "block";

  }}

  //function costcal(){

document.getElementsByName('assignedto')[0].onchange = function() {

  //var asn = document.getElementsById('assignedto').value;

  if (this.value!='') {

  //var asn = document.getElementsById('assignedto').value;

  var asn = gel('assignedto').value;

  //alert('inside'+asn);

  var assignto = new GlideRecord('sys_user');

  assignto.addQuery('sys_id',asn);

  assignto.query();

  if (assignto.next()){

  //alert(assignto.name);

  var cst = assignto.u_cost_center;

  //alert(assignto.u_cost_center);

  //alert(cst);

  if (cst != ''){

  var costcen = new GlideRecord('cmn_cost_center');

  costcen.addQuery('name','STARTSWITH',cst);

  costcen.query();

  if (costcen.next()){

  //var cstname = document.getElementById("costcenter");

  //cstname = costcen.name;

  //alert(costcen.name);

  //alert(cstname);

  //var cstn = gel('costcenter').value;

  //cstn.setvalue = costcen.name;

  gel('costcenter').value = costcen.name;

  document.getElementById("costcenter").value = costcen.name;

  alert(costcen.name);

  //costcen.update();

  //return cstn;

  //document.getElementById("costcenter").value = costcen.name;

  //g:ui_form.setValue('costcenter',costcen.name);

  }}}}}

  function onSubmit(){

  var ast = gel("QUERY:u_asset_state!=1^assigned_toISEMPTY^u_is_shared=false").value;

  //alert(ast);

  var asgn = gel('assignedto').value;

  //alert(asgn);

  var cstcen = gel('costcenter').value;

  var loc = gel('location').value;

  var shr= document.getElementById("shared").checked;

  //var shrdtype = gel('sharedtype').value;

  //var brn = gel('branch').value;

  //var cu = gel('cube').value;

  //var olab = gel('otherlab').value;

  //var otr = gel('other').value;

  if (ast == '') {

  alert('Please Asset Detail');

  return false;}

  if (asgn == '' && shr == false) {

  alert('Please Assignee/Shard Detail');

  return false;}

  if (cstcen == '') {

  alert('Please cost Detail');

  return false;}

  if (loc == '') {

  alert('Please location Detail');

  return false;}

  if (shr == true){

  var shrdtype = gel('my_substate').value;

  //alert(shrdtype);

  if (shrdtype == '--None--'){

  alert('Please select shard type');

  return false;

  }

  if (shrdtype == 'Branch'){

  var brn = gel('branch').value;

  if (brn == '') {

  alert('Please Branch Detail');

  return false;}}

  if (shrdtype == 'Call Center' || shrdtype == 'Workstation Scanner'){

  var cu = gel('cube').value;

  if (cu == '' ) {

  alert('Please Cube Detail');

  return false;}}

  if (shrdtype == 'Other'){

  var otr = gel('other').value;

  if (otr == '') {

  alert('Please Other Detail');

  return false;}}}

  return true;

  }

13 REPLIES 13

That worked! Thanks!


Hi Trevor,



I want to get rid of a drop down value without marking it ''Inactive'' at the backend.


For ex,:   I have a field 'domain' with values Chip, Pond, CDN.


I want to hide CDN without marking it Inactive at the backend using gel.



I am writing following code, but its not working:


if(domainName == "CDN"){


gel('display_hidden.domain_name').value = 'CDN';


//gel('cdn_info').style.display = "inline";


      gel('cdn_info').style.display = "none";


}/*



I was able to hide the CDN values but not CDN itself. Any thoughts?



-Jyo


Hello Jyo,



Your question appears to be off-topic as we are discussing macro reference fields here. You should find the following discussion relevant to your question: How to hide choices from choice list using client script onchange



There are a handful of other similar discussions. If none of those meet your needs, feel free to create a new discussion and message me.



- Trevor Muhl


I think the display_hidden is the display value for the other 5th value: "sys_original".



Even when I do not clear the value using script, but rather just manually by clicking on the X on the field it self,


I can still see that hidden_display and sys_original is still present.



This makes me suspect that these two fields are intended for the pervious/new value concept,


used by for example client scripts when validating if value changed or not and such.



I think you should leave these two as is.


gowthamanbalu
Tera Contributor

Thank you so much Kalai.. It works!!!