Is there any way to call script include synchronously from service portal other than getXMLWait()

Prateek Gupta3
Mega Guru

Hi All,

 

Is there any way to call script include synchronously from service portal other than getXMLWait()?

I am using getXMLWait() in onSubmit client scripts.

 

 

Thanks in advance.

Prateek Gupta

 

8 REPLIES 8

Daniel Draes
ServiceNow Employee
ServiceNow Employee

As the Service Portal is based on Angular I am wondering why you would need an Ajax Call separately. Shouldn't you just use the client / controller piece of Angular?

mehak1890
Tera Expert

Hi Chuck/ Fogg,

I'm also facing same issue, my onsubmit client script also not working due to getxmlwait in service portal. Its working in ServiceNow but in portal i'm getting java console error.

OnSubmit client script:

function onSubmit() {
if(g_form.getValue('field name') == 'Yes'){
var ga = new GlideAjax('xxxxx');
ga.addParam('sysparm_name','attachmentExists');
ga.addParam('sysparm_record_id',g_form.getValue('sysparm_item_guid'));
ga.getXMLWait();
var attachment = ga.getAnswer();
if(attachment == "false"){
g_form.addErrorMessage(getMessage("message1"));
g_form.addInfoMessage(getMessage("messsgae2"));
return false;
}}}

Script include:

var xxxxx = Class.create();
CheckAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {

attachmentExists: function() {
var attachmentGR = new GlideRecord('sys_attachment');
var record_id = this.getParameter('sysparm_record_id');
attachmentGR.addQuery("table_sys_id", record_id);
attachmentGR.query();

if(attachmentGR.next()) {
return true;
}
return false;
},

type: 'xxxxx'
});

 

Could you pls urgent help how it will work, I tried lot of things but its not working in Portal page. Thanks, Mehak

Hi,

Use below client script:

 

function onSubmit() {
if(g_form.getValue('field name') == 'Yes'){
var ga = new GlideAjax('xxxxx');
ga.addParam('sysparm_name','attachmentExists');
ga.addParam('sysparm_record_id',g_form.getValue('sysparm_item_guid'));
ga.getXML(callback);

function HelloWorldParse(response) { var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == "false"){
g_form.addErrorMessage(getMessage("message1"));
g_form.addInfoMessage(getMessage("messsgae2"));
return false;
}

}

}

Thanks,
Ashutosh Munot

You can write before/insert  business  rule and after GlideRecord use current.setAbortAction(true);.