UI Page get value from g:ui_reference and pass to script include

reginabautista
Kilo Sage

Hi guys,

I have two reference fields on a UI Page. I would like the second reference field to display values depending on what's selected on the first reference field and pass this value to a script include. Would you know how to achieve this? My code javascript:busServiceBulkUpdateQuery($('channel').value)does not work.. goranlundqvist any ideas?

<div class="form-group">

  <label class="reference-label">${gs.getMessage('Channel')}</label>

  <g:ui_reference class="col-xs-12" name="channel" table="u_cmdb_ci_service_channel" query="u_active=true" />

  </div>

  <div class="form-group">

  <label class="reference-label">${gs.getMessage('Business Service')}</label>

  <g:ui_reference name="bus_svc" table="u_cmdb_ci_service_business" query="javascript:busServiceBulkUpdateQuery($('channel').value)" />

  </div>

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Regina,



I have posted something similar on below links i.e. second ui reference should be dependent on first ui reference. Not sure on the script include part you are asking.


I achieved it without using script include.



How to make assigned_to field dependent on assignment group on a UI page


Change ui reference query


Reference field dependency on UI Page



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

No links are workinf

reginabautista
Kilo Sage

Hi Ankur



I've moved my reply here as I've realized I was replying to another thread earlier.



I think the filtering is being ignored as when I click on the url of Business Service dialog it goes to this:



https://myinstance.service-now.com/u_cmdb_ci_service_business_list.do?sysparm_target=bus_svc&sysparm...u_active%3Dtrue&sysparm_domain_restore=false



Notice that the sysparm_additional_qual=u_active%3Dtrue (this is the correct field with u_ in front)




but in the client script it was set to active=true. (Incorrect field) I purposely kept it this way to test if the filtering really is being called and applied but it looks like it doesnt. I tested the GR code in background scripts and it setting the array correctly.




I don't know what's wrong...




function setChannelFilter(){



var busSvcLkp = gel('lookup.bus_svc');


var sysIdArray = [];



var gr = new GlideRecord('u_cmdb_ci_service_business');


gr.addEncodedQuery('sys_class_nameINSTANCEOFcmdb_ci_service^u_parent_m2m=bde6a5abd5b90500aa69448450c55629');


gr.query();


while(gr.next()){


sysIdArray.push(gr.sys_id.toString());


}



busSvcLkp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'bus_svc', 'not', 'u_cmdb_ci_service_business', '', 'false','QUERY:active=true', 'sys_idIN" + sysIdArray+ "', '')");


}


https://betfairdev.service-now.com/u_cmdb_ci_service_business_list.do?sysparm_target=bus_svc&sysparm...


Hi Ankur



I did some debugging and it appears addEncodedQuery does not work on this context. I was getting 'addEncodedQuery is not a function' error.



I have used addQuery instead and this has resolved the issue. Thank you for the help!



function setChannelFilterA(){


  try{


alert('setChannelFilterA start');


var channel = gel('channel').value;


var busSvcLkp = gel('lookup.bus_svc');


var sysIdArray = [];



var gr = new GlideRecord('u_cmdb_ci_service_business');


//gr.addEncodedQuery('sys_class_nameINSTANCEOFcmdb_ci_service^u_parent_m2m=bde6a5abd5b90500aa69448450c55629');


gr.addQuery('u_active',true);


gr.addQuery('u_parent_m2m',channel);


gr.query();


while(gr.next()){


sysIdArray.push(gr.sys_id.toString());


}



busSvcLkp.setAttribute('onclick',"mousePositionSave(event); reflistOpen( 'bus_svc', 'not', 'u_cmdb_ci_service_business', '', 'false','QUERY:u_active=true', 'sys_idIN" + sysIdArray+ "', '')");


alert('setChannelFilterA end');


}catch(err){


console.log(err.message);


}


}


Hi Regina,



Great that it worked. Could you also endorse the content. Thanks in advance.


How to Endorse Content



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader