- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-04-2021 09:43 AM
Hello.
I have three reference fields on UI page: Company, Code & Type.
On click of UI action I'm able to populate those fields from form to UI page.
When I change company then the other two fields (values from fields) should get cleared. I'm able to achieve this using gel('<field>').value =''; and gel('sys_display.<field>').value='';
The issue is, when I select value from other two reference fields it is not showing. May be it gets cleared again.
I would really appreciate if I get any kind of help here.
TIA.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-06-2021 07:40 AM
Thank you for your time Kieran & Ankur, I really appreciate. I resolved the issue.
Every time that function gets called. So, I simply wrote onchange attribute and declared a function in urgency & style. Below is the changes I made.
HTML:
<g:ui_reference name="u_urgency_code" id="u_urgency_code" completer="AJAXTableCompleter" table="u_fsmm_urgency_code" displayValue="${jvar_urgencyDisplayName}" value="${jvar_urgencyCode}" query="u_active=true^u_company=${jvar_companyName}" onchange="changeUrgency()" />
<g:ui_reference name="u_pcd_style" id="u_pcd_style" completer="AJAXTableCompleter" table="u_pcd" displayValue="${jvar_styleDisplayName}" value="${jvar_styleName}" query="u_active=true^u_company=${jvar_companyName}" onchange="changeStyle()" />
Updated Client script:
function changeUrgency() {}
function changeStyle() {}
function showUrgencyAndStyle() {
var companyId = gel('company').value;
var urgencyId = gel('u_urgency_code').value;
var styleId = gel('u_pcd_style').value;
var urgencyLookUp = gel('lookup.u_urgency_code');
var styleLookUp = gel('lookup.u_pcd_style');
var urgencyArray = [];
var styleArray = [];
gel('u_urgency_code').value = "";
gel('sys_display.u_urgency_code').value = "";
urgencyLookUp.style.display = "none";
gel('u_pcd_style').value = "";
gel('sys_display.u_pcd_style').value = "";
styleLookUp.style.display = "none";
if (companyId != '') {
urgencyLookUp.style.display = "";
styleLookUp.style.display = "";
//Filter for Urgency code based on company
var grUrgency = new GlideRecord("u_fsmm_urgency_code");
grUrgency.addQuery('u_active', true);
grUrgency.addQuery('u_company', companyId);
grUrgency.addQuery("u_urgency_code", "!=", "");
grUrgency.query();
while (grUrgency.next()) {
urgencyArray.push(grUrgency.sys_id.toString());
}
urgencyLookUp.setAttribute('onclick', "mousePositionSave(event); reflistOpen('u_urgency_code', 'not', 'u_fsmm_urgency_code', '', 'false', 'QUERY:u_active=true', 'sys_idIN" + urgencyArray + "', '')");
//Filter for Style based on company
var grStyle = new GlideRecord("u_pcd");
grStyle.addQuery('u_active', true);
grStyle.addQuery('u_company', companyId);
grStyle.addQuery("u_style", "!=", "");
grStyle.query();
while (grStyle.next()) {
styleArray.push(grStyle.sys_id.toString());
}
styleLookUp.setAttribute('onclick', "mousePositionSave(event); reflistOpen( 'u_pcd_style', 'not', 'u_pcd', '', 'false', 'QUERY:u_active=true', 'sys_idIN" + styleArray + "', '')");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-05-2021 06:08 AM
I am not clear with the part and confused.
If the filters are set correctly based on company change then what's the issue
you are only setting the filter and not setting the value
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
ā01-05-2021 06:15 AM
I'm also confused.
If I select other company (say EFGH) and urgency code consists of 3 values (say aa, bb & cc) and if I select any one value, it is not showing on fields.
I don't know what should be done.
I think, below code is clearing values every time.
gel('u_urgency_code').value = "";
gel('sys_display.u_urgency_code').value = "";
gel('u_pcd_style').value = "";
gel('sys_display.u_pcd_style').value = "";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-05-2021 06:32 AM
Hi,
but this script will only run when company changes
If you are able to test below scenario then you should be ok
1) Consider this scenario
a) You select Company EFGH
b) On Change would run and clear both the fields and set the filter
c) you should be able to select the Urgency and Style Now
d) now you clear the Company and set it to DEF
e) Again on change runs and clear both the fields and set the filter
f) user can select urgency and Style
g) Now if you clear company and make it empty
h) again onchange runs and clear the value
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
ā01-05-2021 06:41 AM
The issue is with below line.
c) you should be able to select the Urgency and Style Now.
Actually, I am able to select urgency but the selected value is getting cleared again; that selected value is not showing. Same is happening with Style.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-05-2021 06:48 AM
Hi,
but you are not having any onchange attribute for those 2 <g:ui_reference> tags
Did you try adding alert here and check if this function is getting triggered?
function showUrgencyAndStyle() {
alert('inside change');
var companyId = gel('company').value;
var urgencyLookUp = gel('lookup.u_urgency_code');
var styleLookUp = gel('lookup.u_pcd_style');
var urgencyArray = [];
var styleArray = [];
if (companyId == '' || companyId == 'null') {
gel('u_urgency_code').value = "";
gel('sys_display.u_urgency_code').value = "";
gel('sys_display.u_urgency_code').readOnly = true;
urgencyLookUp.style.display = "none";
gel('u_pcd_style').value = "";
gel('sys_display.u_pcd_style').value = "";
gel('sys_display.u_pcd_style').readOnly = true;
styleLookUp.style.display = "none";
return;
}
else{
gel('u_urgency_code').value = "";
gel('sys_display.u_urgency_code').value = "";
gel('u_pcd_style').value = "";
gel('sys_display.u_pcd_style').value = "";
//Filter for Urgency code based on company
var grUrgency = new GlideRecord("u_fsmm_urgency_code");
grUrgency.addQuery('u_active', true);
grUrgency.addQuery('u_company', companyId);
grUrgency.addQuery("u_urgency_code", "!=", "");
grUrgency.query();
while (grUrgency.next()) {
urgencyArray.push(grUrgency.sys_id.toString());
}
urgencyLookUp.setAttribute('onclick', "mousePositionSave(event); reflistOpen('u_urgency_code', 'not', 'u_fsmm_urgency_code', '', 'false', 'QUERY:u_active=true', 'sys_idIN" + urgencyArray + "', '')");
//Filter for Style based on company
var grStyle = new GlideRecord("u_pcd");
grStyle.addQuery('u_active', true);
grStyle.addQuery('u_company', companyId);
grStyle.addQuery("u_style", "!=", "");
grStyle.query();
while (grStyle.next()) {
styleArray.push(grStyle.sys_id.toString());
}
styleLookUp.setAttribute('onclick', "mousePositionSave(event); reflistOpen( 'u_pcd_style', 'not', 'u_pcd', '', 'false', 'QUERY:u_active=true', 'sys_idIN" + styleArray + "', '')");
}
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader