UI Page not rendering when passing parameters from UI action

ray evans
Tera Guru

Hi

 

I have a UI action (client with Onclick) on Incident, in which I am trying to pass the SysId and CI to a UI page. However, the dialog window does not render unless I remove the "dialog.addParam" lines

 

function updateAsset(){
 var sys_id = g_form.getUniqueValue();
 var dialog = new GlideDialogWindow('update_asset');
 dialog.setTitle("Update Asset");
 dialog.setHeight(800);
 dialog.setWidth(600);
 dialog.addParam('sys_id', sys_id);
 dialog.addParam('ci', cmdb_ci);
 dialog.render();
}
 
Can someone please point me in the right direction as to what I'm doing wrong? And also how to populate fields on the UI page with these values?
 
Thanks
 
Ray
22 REPLIES 22

@Ankur Bawiskar  If you mean the ui action script I have already done so but it still doesn't open.

 

function updateAsset(){
var sys_id = g_form.getUniqueValue();

var cmdb_ci = g_form.getValue('cmdb_ci');
var dialog = new GlideDialogWindow('update_asset');
dialog.setTitle("Update Asset");
dialog.setHeight(800);
dialog.setWidth(600);
dialog.addParam('sys_id', sys_id);
dialog.addParam('ci', cmdb_ci);
dialog.render();
}

@ray evans 

this UI action script is fine.

I am referring that you should be able to get the values of those 2 fields to UI page and then you can proceed in UI page script

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

Hi @Ankur Bawiskar 

 

I was able to retrieve and set the value using this script:

 

function onLoad() {
  console.log("onLoad event fired");

  // Retrieve the sys_id from URL parameters
  var urlParams = new URLSearchParams(window.location.search);
  var sysId = urlParams.get('sys_id');

  console.log("sysId:", sysId);

  // Create a new instance of GlideRecord
  var gr = new GlideRecord('incident');
  gr.addQuery('sys_id', sysId);
  gr.query();

  if (gr.next()) {
    var fieldValue = gr.getValue('number');
    console.log("Matching Record Found:", fieldValue);

    // Set the value of the 'incident' field directly
    document.getElementById('incident').value = fieldValue;
    console.log("Field value set:", document.getElementById('incident').value);

    // Set the value of the 'incident' field using a callback function
    g_form.addInfoMessage('Setting field value...');
    g_form.setValue('incident', fieldValue);
    console.log("Field value set:", g_form.getValue('incident'));
  } else {
    console.error("Incident record not found with sys_id:", sysId);
  }
}

// The onLoad() function will be automatically invoked when the page loads
onLoad();

 

The console logs confirm this is successful but the incident field is not populated the the page loads

@ray evans 

what is this line doing?

g_form.setValue('incident', fieldValue);

also you are not updating the record using gr object

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

@Ankur Bawiskar it appears to set the value but doesn't display it when the page loads - here are the logs which confirm the value is set

 

onLoad event fired
VM27475:8 sysId: 05c307621bdea510349f40c4e34bcb9d
js_includes_doctype.jsx?v=05-15-2023_1848&lp=Tue_Jun_13_03_16_55_PDT_2023&c=8_102:870 [00:00:00.079] *** WARNING *** GlideAjax.getXMLWait - synchronous function - processor: AJAXGlideRecord
js_includes_doctype.jsx?v=05-15-2023_1848&lp=Tue_Jun_13_03_16_55_PDT_2023&c=8_102:16858 *** WARNING *** GlideAjax.getXMLWait - synchronous function - processor: AJAXGlideRecord
js_includes_doctype.jsx?v=05-15-2023_1848&lp=Tue_Jun_13_03_16_55_PDT_2023&c=8_102:870 [00:00:00.081] *** WARNING *** GlideRecord synchronous query for table: incident
VM27475:17 Matching Record Found: INC0117518
VM27475:21 Field value set: INC0117518
VM27475:26 Field value set: INC0117518

 

I am not updating the record at this point - I have a continueOK() script which updates the relevant record when the ui page is submitted.