- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 02:53 AM
Hi Community,
I'm creating a Ui page(see the attached) for consumables the issue is when I select the stock room the model field should show only the models available in that stockroom, can someone please help me how to write the code for the above condition.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 04:37 AM
Hi,
update as this
HTML:
<td>Stockroom: </td>
<td> <g:ui_reference name="stockroom" id="stockroom" table="alm_stockroom" completer="AJAXTableCompleter" onchange="fetchModels()"/></td>
</tr>
<tr>
<td>Model: </td>
<td>
<g:ui_reference name="model" id="model" table="alm_consumable"/></td>
</tr>
Client Script:
function fetchModels(){
var stockroomValue = gel('stockroom').value;
var models = gel('lookup.model');
var modelArray = [];
var gr = new GlideRecord("alm_consumable");
gr.addQuery("stockroom", stockroomValue);
gr.query();
while (gr.next()) {
modelArray.push(gr.sys_id.toString());
}
models.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'model', 'not', 'alm_consumable', '', 'false','QUERY:active=true', 'sys_idIN" + modelArray+ "', '')");
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 03:12 AM
Hi,
I have implemented such scenario in past.
I had two reference field in UI page as shown below,
Example UI page having two reference field.
UI Page :
<table>
<tr>
<td >Source</td>
<td><g:ui_reference id="source" name="source" table="sys_user" completer="AJAXTableCompleter" query="active=true" onChange="setUserFilter()" /></td>
</tr>
<tr>
<td>Target</td>
<td><g:ui_reference id="target" name="target" table="sys_user" completer="AJAXTableCompleter" onChange="clearFilter()"/></td>
</tr>
</table>
Client Script :
function setUserFilter() {
var sysIDSource = gel('source').value;
var UserLookUp = gel('lookup.target');
if(gel('target').value != ''){
document.getElementById('sys_display.target').value = '';
document.getElementById('target').value = '';
document.getElementById('targetLINKreplace').style.display = 'none';
}
//Get your stock record sys_id's through GlideAjax and store it in 'array', we have used same array object in below target field.
UserLookUp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'target', 'not', 'sys_user', '', 'false','QUERY:active=true', 'sys_idIN" + array+ "', '')");
}
For more details you can refer below discussion where I asked similar question and Ankur provided the solution and it worked for me.
Make sure you use GlideAjax in client script instead of using GlideRecord in client script as mentioned in the discussion.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 03:32 AM
sharing few links which should help you;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 04:29 AM
Hi Ankur,
I'm using the below script but not working
HTML:
<td>Stockroom: </td>
<td> <g:ui_reference name="stockroom" id="stockroom" table="alm_stockroom" completer="AJAXTableCompleter" onchange="fetchModels()"/></td>
</tr>
<tr>
<td>Model: </td>
<td>
<g:ui_reference name="cmdb_model" id="model" table="alm_consumable" query="stockroom=storkroom"/></td>
</tr>
client script:
function fetchModels(){
var stockroomValue = gel('stockroom').value;
var models = gel('lookup.model');
var modelArray = [];
var gr = new GlideRecord("alm_consumable");
gr.addQuery("location", stockroomValue);
gr.query();
while (gr.next()) {
modelArray.push(gr.sys_id.toString());
}
models.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'model', 'not', 'alm_consumable', '', 'false','QUERY:active=true', 'sys_idIN" + modelArray+ "', '')");
}
I'm also not sure where to fetch the model, right now I'm trying to fetch from alm_consumable table
can you please help if I did anything wrong in the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 04:37 AM
Hi,
update as this
HTML:
<td>Stockroom: </td>
<td> <g:ui_reference name="stockroom" id="stockroom" table="alm_stockroom" completer="AJAXTableCompleter" onchange="fetchModels()"/></td>
</tr>
<tr>
<td>Model: </td>
<td>
<g:ui_reference name="model" id="model" table="alm_consumable"/></td>
</tr>
Client Script:
function fetchModels(){
var stockroomValue = gel('stockroom').value;
var models = gel('lookup.model');
var modelArray = [];
var gr = new GlideRecord("alm_consumable");
gr.addQuery("stockroom", stockroomValue);
gr.query();
while (gr.next()) {
modelArray.push(gr.sys_id.toString());
}
models.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'model', 'not', 'alm_consumable', '', 'false','QUERY:active=true', 'sys_idIN" + modelArray+ "', '')");
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader