How to pass a reference value from form to UI page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 10:34 AM - edited 04-03-2023 10:39 AM
Hello All,
I am trying to pass a reference value which is already on the form onto a UI page pop-up through UI Action.
In my Case, when clicked on "Promote to Major Incident" UI page opens up "mim_workbench_promote".
In addition to Work notes and Business Impact, Service is also added to this UI Action which is same as "Service" on the Incident Form.
When Service on the form is filled in and saved, and then when this UI action is selected, the UI page pops-up and the value which is already on the form must pre-populate on the UI Page, but this isn;t happening.
It is working smooth with the text field, but as this is a reference field, the UI Page might be expecting something else in a specific format.
UI Action : (Added this)
dialog.setPreference('SERVICE', g_form.getValue('business_service'));
UI Page:
HTML:
<div class="form-group" id="service-wrapper">
<label class="col-sm-2 control-label" for="mim-promote-service">
<span mandatory="true" class="required-marker label_description"></span>
${gs.getMessage('Service')}</label>
<div class="col-sm-10">
<g:ui_reference name="mim-promote-service" id="mim-promote-service" table="cmdb_ci_service" completer="AJAXTableCompleter" oninput="promoteModal.workNotesOnChange()" onchange="promoteModal.workNotesOnChange()"/>
</div>
</div>
Client script:
var service = $("mim-promote-service");
var serviceWrapper = $('service-wrapper');
//This is currently existing
var currentBusinessImpact = dialog.getPreference('BUSINESS_IMPACT');
if (currentBusinessImpact)
businessImpact.value = currentBusinessImpact;
//This is currently added
var currentService = dialog.getPreference('SERVICE');
if (currentService){
service.value = currentService;
//I am getting service.value as sys_id which is selected on the form
//Added these 2 lines in promote Function
record.business_service = service.value;
//added this in else part
g_form.setValue('business_service', service.value);
//Modified "workNotesOnChange" as below.
function workNotesOnChange() {
workNotes.value.trim() ? workNotesWrapper.addClassName('is-filled') : workNotesWrapper.removeClassName('is-filled');
service.value ? serviceWrapper.addClassName('is-filled') : serviceWrapper.removeClassName('is-filled');
alert("worknotes "+workNotes.value.trim() + "Service" + service.value);
(workNotes.value.trim() && service.value) ?
(promoteBtn.removeClassName('disabled'), promoteBtn.writeAttribute('aria-disabled', false)) :
(promoteBtn.addClassName('disabled'), promoteBtn.writeAttribute('aria-disabled', true));
}
Part of this is being in this How to add a reference field when clicked on a UI Action . Kindly refer for more clarity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 12:18 PM
Hi @Akhila Vangala ,
I am not sure whether tis is the right solution or not but you can try and let us know if the below changes has worked or not.
in the UI Action use the below code:
var service =g_form.getReference('business_service');
dialog.setPreference('SERVICE', g_form.getValue('business_service'));
dialog.setPreference('SERVICE_NAME', service.name);
in the HTML Code change the <g:ui_reference> tag as below.
<g:ui_reference name="mim-promote-service" id="mim-promote-service" table="cmdb_ci_service" completer="AJAXTableCompleter" value="${SERVICE}" displayvalue="${SERVICE_NAME}" oninput="promoteModal.workNotesOnChange()" onchange="promoteModal.workNotesOnChange()"/>
Mark helpful if it helps in solving your query.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 12:42 PM
I got this error after keeping everything at place.