Access to getXMLWait is not available in scoped applications , what is workaround ?

nthumma
Giga Guru

I am trying to query related list on submit and i am getting 'Access to getXMLWait is not available in scoped applications' infomessage on the form.

I am trying to do something similar to Make entry in related list mandatory

any workarounds?

25 REPLIES 25


Hi Elliott, you need to use Asynchronous GlideAJAX and pass in a callback function to get the response (instead of a synchronous call that waits for the response before continuing).

In the response callback you can stop the form submission and show a message or continue the submission based on the result conditions.

Try this code below, note this isn't tested but should help to point you in the right direction. Let me know if you have any questions.

 

function onSubmit() {

  // Check if submission is valid
  if (g_scratchpad.isAttachmentValid) {
    return true;
  }

  var q510 = g_form.getValue('service_needed_510');

  if (q510 == 'Restore - database') {

    var cat_id = gel('sysparm_item_guid').value;

    var ga = new GlideAjax('ServiceCatalogAJAX');

    ga.addParam('sysparm_name', 'requireAttachment');

    ga.addParam('sysparm_cat_id', cat_id);

    // Get response from server asynchronously and pass in getAttachmentResponse callback method as a parameter
    ga.getXMLAnswer(getAttachmentResponse);

  }

  // Return false here to stop submission while awaiting the asynchronous response
  return false;
}

// Get response callback
function getAttachmentResponse(attachment_response) {

  if (attachment_response == 'true') {

    // Accept valid submission 
    g_form.submitted = true;
    g_scratchpad.isAttachmentValid = true;
    g_form.submit(g_form.getActionName());
    return true;

  } else {
    // Stop submission
    g_form.submitted = false;
    g_form.addErrorMessage("Alert! Attach the email generated by your request submitted on the HSG site.");
    return false;

  }
}

THANK YOU!!!

 

I will try this out soon (when I am back to working on this form) and let you know my results.

I don't think the scratchpad functionality is supported in a client script in a scoped application so I added a 'hidden' check box field on the catalog item called "submitted" and made some changes to the script. Now, I will run however, it seems to get stuck and does nothing after presenting the alerts (listed below).

 

=========== start of script ======================

 

function onSubmit() {
 
 
 alert('RequireAttachment IS RUNNING');
 
 var submitted = g_form.getValue('submitted');
 alert('submitted: ' + submitted);
 
 if (submitted == 'true') {// this prevents recursion
  return true;
 }
 
 var q53 = g_form.getValue('computer_hardware_requirements_53');
 alert('q53: ' + q53);
 
 if(q53 == 'UHG nonstandard developer laptop docking station included lock required' || q53 == 'UHG nonstandard developer desktop monitor keyboard and mouse included') {
  
  alert('Condition met, checking if there is an attachment');
  
  var cat_id = gel('sysparm_item_guid').value;
  alert('cat_id: ' + cat_id);
  var ga = new GlideAjax('ServiceCatalogAJAX');
  ga.addParam('sysparm_name', 'requireAttachment');
  ga.addParam('sysparm_cat_id', cat_id);
  
  // Get response from server asynchronously and pass in getAttachmentResponse callback method as a parameter
  ga.getXMLAnswer(getAttachmentResponse);
  alert('answer returned');
  
 }
 
 // Return false here to stop submission while awaiting the asynchronous response
 return false;
}

// Get response callback
function getAttachmentResponse(attachment_response) {
 
 alert('performing callback');
 alert('attachment_response: ' + attachment_response);
 
 if (attachment_response == 'true') {
  
  // Accept valid submission
  g_form.setValue('submitted', 'true'); // set the hidden value to prevent recursion
  g_form.submit(g_form.getActionName());
  return true;
  
 } else {
  // Stop submission
  g_form.addErrorMessage("Alert! The Developer System Questionnaire must be completed and attached to this request.");
  return false;
  
 }
}

=========== end of script ======================

 

BEGIN RESULTS

The result is that it returns the following alerts and then stops and does nothing;

RequireAttachment IS RUNNING

submitted: false

q53: UHG nonstandard developer laptop docking station included lock required

Condition met, checking if there is an attachment

cat_id: 1285b4f3dbb82744967aa895ca961978

answer returned

END RESULTS

 

I'm not sure where to go at this point. Any thoughts/revisions/suggestions would be greatly appreciated.

Thanks again for your help with this. 🙂

B_10
Tera Contributor

Thank you

Chris Sanford1
Kilo Guru

I've never had to do this myself (fortunately), but what about using a scripted REST API and calling that from your client script?