Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Building a UI Page, Issue using GlideAjax in Client script

Kapil Chopra
Tera Contributor

I am trying to get value in UI Page Client Script via GlideAjax,however when I try to destroy the window it doesn't close the UI page or save the record.

This UI Page is called via UI action has only one reference field 

 

var gaLoc = new GlideAjax('someutil');
gaLoc.addParam('sysparm_name', 'getLocation');
gaLoc.addParam('sysparm_assignmentGrp', 'Location');
gaLoc.getXML(assgnLocSysid);

// the callback function for returning the result from the server-side code
function assgnLocSysid(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('assignment_group', assigmentgrp);
g_form.setValue('location', answer);
GlideDialogWindow.get().destroy();
g_form.save();

}

 

1 ACCEPTED SOLUTION

Not applicable

try :

 

var gaLoc = new GlideAjax('someutil');
gaLoc.addParam('sysparm_name', 'getLocation');
gaLoc.addParam('sysparm_assignmentGrp', 'Location');
gaLoc.getXML(assgnLocSysid);

function assgnLocSysid(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  g_form.setValue('assignment_group', assigmentgrp);
  g_form.setValue('location', answer);
  g_form.save();
  GlideDialogWindow.get().destroy();
}

View solution in original post

6 REPLIES 6

Neel Patel
Tera Guru

Can you try switching the last 2 line order?

You should save the form before destruction the Modal.

Ok will try and update , however same sequence without any Ajax calls and hard-coded value works. 

Not applicable

try :

 

var gaLoc = new GlideAjax('someutil');
gaLoc.addParam('sysparm_name', 'getLocation');
gaLoc.addParam('sysparm_assignmentGrp', 'Location');
gaLoc.getXML(assgnLocSysid);

function assgnLocSysid(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  g_form.setValue('assignment_group', assigmentgrp);
  g_form.setValue('location', answer);
  g_form.save();
  GlideDialogWindow.get().destroy();
}

Kapil Chopra
Tera Contributor

After making the changes to the code ,now assignment group gets set, however location is still undefined and the form doesn't save because location is mandatory. it seems due to GlideAjax we don't  get value of location before g_form.save.