Not able to call a script include function from a UI page using GlideAjax

Rahul Chand
Tera Contributor

I am using GlideAjax to call a script include function 'acceptPayment' from a UI page but it is not able to run the function , both UI page and script include are in same scope and when I try to run the script include from the same GlideAjax code from a widget it works perfectly fine. 

This is my client script code :

 

function myFunction() {
var number = document.getElementById('number').value;
var paymentId = document.getElementById('paymentId').value;
var PayerID = document.getElementById('PayerID').value;
 
var ga = new GlideAjax('global.PaypalAPI');
 
ga.addParam('sysparm_name','acceptPayment');
ga.addParam('sysparm_payment_id',paymentId);
ga.addParam('sysparm_payer_id',PayerID);
ga.addParam('sysparm_record_number',number);
 
ga.getXML(myCallBack);
}
 
 
 
and below is the script include function 'accept payment':

acceptPayment: function() {
gs.info('abcd acceptPayment');
var token = this.getToken();
var payer_id = this.getParameter('sysparm_payer_id');
        var payment_id = this.getParameter('sysparm_payment_id');
var record_number = this.getParameter('sysparm_record_number');
        if (token[0] == 200){
try {
var r = new sn_ws.RESTMessageV2('paypal', 'Accept Payment');
r.setStringParameterNoEscape('payer_id', payer_id);
r.setStringParameterNoEscape('token', token[1]);
r.setStringParameterNoEscape('payment_id', payment_id);
 
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
if(httpStatus == 200 || httpStatus == '200'){
}
} catch (ex) {
var message = ex.message;
}
}
    }
 
 
myFunction();
 
function myCallBack(response){
var redirectUrl = response.responseXML.documentElement.getAttribute('answer');
top.window.location.href=redirectUrl;
}
 
 
8 REPLIES 8

Thanks for reply, but this code doesn't help. 

Ankur Bawiskar
Tera Patron
Tera Patron

@Rahul Chand 

how is that UI page getting invoked? from UI action etc?

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

It is the processing page of a payment gateway which gets redirected after the payment to check if the payment is succeed or not.

@Rahul Chand 

so the UI page is being opened as part of some redirection

Did you try adding alert in the Client script section of UI page?

Give the HTML code of the UI page and the client script here

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