Catalog Client Script (GlideAjax) throwing error on Portal "There is a JavaScript error ........"

chatsaurav19
Tera Contributor

Hi Team,

 

While using a CCS, ( attached screen shot ) in which I have made a GlideAjax call, I am getting a error stating "There is a JavaScript error in your browser console". The values are getting populated in the back end instance while 'try it' but in portal it is throwing the error. 

 

I need the data to populate the Catalog Item Fields on the Portal. Any suggestion as to how can I achieve this?

 

Regards,

Saurabh

1 ACCEPTED SOLUTION

@chatsaurav19 

 

It seems that g_user.getUserID() is not supported in Service portal 

https://www.servicenow.com/community/developer-forum/g-user-getuserid-alternate-options-in-service-p...

 

 

You can do one thing instead of sending it from front end, please get the loggedin user in the backend itself as gs.getUserID() (inside script include);

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

View solution in original post

6 REPLIES 6

Prince Arora
Tera Sage
Tera Sage

@chatsaurav19 ,

 

As I have seen you used getXMLAnswer in the script,  getXMLAnswer is not supported in Service portal, it is supported in Native UI

 

Please try to update the getXMLAnswer to getXML it will not through the error, but it is dependent completely on your use case

 

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact.

Hi @Prince  Nope it is still showing the same error

@chatsaurav19 

 

Can you share your updated code?

 

 

function onLoad() {
//Type appropriate comment here, and begin script below
g_form.setValue('requested_for', g_user.getFullName());

var ga1 = new GlideAjax('GetUserDetails');
ga1.addParam('sysparm_name', 'GetUserDetail');
ga1.addParam('sysparm_userid', g_user.getUserID());
ga1.getXML(callback);

function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//answer = JSON.parse(answer);
g_form.setValue('requester_manager', answer);
g_form.setValue('location', answer[1]);
g_form.setValue('email', answer[2]);