How to execute client callable script include in background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 01:20 AM
hi all,
i want to test client callable script include. Is there any way to test this in background script.
sample code snippet:
var Userlocationfetch = Class.create();
Userlocationfetch.prototype = Object.extendsObject(AbstractAjaxProcessor, {
locationDetails: function() {
var userID = this.getParameter("sysparm_user");
var grUser = new GlideRecord('sys_user');
// logic here
//return location
return JSON.stringify(location);
},
type: 'Userlocationfetch'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 01:34 AM
Hi @Ujjwal1 ,
To execute a client callable script include from a background script, you can use the GlideAjax class.
Here is an example of how to do it:
// Instantiate the client callable script include
var userLocationFetch = new Userlocationfetch();
// Create a new GlideAjax object
var ga = new GlideAjax('Userlocationfetch');
// Set the name of the client callable method to call
ga.addParam('sysparm_name', 'locationDetails');
// Set the user parameter to pass to the method
ga.addParam('sysparm_user', 'user_sys_id_here');
// Execute the AJAX call and get the response
var response = ga.getXMLWait();
// Parse the response as JSON
var location = JSON.parse(response.responseText);
// Do something with the location object
If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the ✅Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.
Thank you!
Ratnakar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 02:40 AM
Following changes make a script include usable from both client and server side.
Script Include
var Userlocationfetch = Class.create();
Userlocationfetch.prototype = Object.extendsObject(AbstractAjaxProcessor, {
locationDetails: function(userSysID) {
var userID = this.getParameter("sysparm_user")?this.getParameter("sysparm_user"):userSysID;
var grUser = new GlideRecord('sys_user');
var location = '';
if(grUser.get('sys_id',userID)){
location = grUser.getDisplayValue('location');
}
// logic here
//return location
return location;
},
type: 'Userlocationfetch'
});
Here is how you are going to call it in the background script.
var user = new global.Userlocationfetch();
gs.print(user.locationDetails(gs.getUserID()));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 12:23 AM
have you passed sys_id of that which user