- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 07:04 AM
Hi,
Can some one will help me out Scriptinclude and Glideajax with real time scenario.
Please explain with real time use case.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 07:34 AM
Please check the below script to know about how to return multiple values from Script include to Client script using JSON.
OnChange Client Script on user field :
var abc = new GlideAjax("Script Include Name");
abc.addParam("sysparm_name", 'FunctionName');
abc.addParam("sysparm_userID", newValue);
abc.getXML(Hello);
function Hello(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);
g_form.setValue("email", answer.firstName); //firstName is the obj name stored in Script include
g_form.setValue("department", answer.lastName);
g_form.setValue("manager", answer.Manager);
}
}
Client - Callable Script include:
var Autopopulate = Class.create();
Autopopulate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
myfunction: function(){
var name = {}; // to store multiple values
var usr = this.getParameter('sysparm_userID');
var tab = new GlideRecord("sys_user");
tab.addQuery("sys_id",usr);
tab.query();
if(tab.next()){
name.firstName = tab.getValue("first_name");
name.lastName = tab.getValue("last_name");
name.Manager = tab.getDisplayValue("manager");
}
return JSON.stringify(name);
},
type: 'Autopopulate'
});
In this way you can return multiple values using JSON.
Please mark it as correct if it resolved your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 07:19 AM
Let's Assume there is a reference field named as User which is referenced to sys_user table.
When we select any user then the user email,mobile phone, manager will be populated in the respected field in the form.
To achieve this we have to create an Onchange client script for the particular table for change of User field.
We have to call the script include from client script.We have to fetch the server side data in the script include and pass it to the client side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 07:23 AM
Hi @Satyapriya
Thanks for the response please help me out with populating the user details by using the scrip include and GlideAjax.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 07:34 AM
Please check the below script to know about how to return multiple values from Script include to Client script using JSON.
OnChange Client Script on user field :
var abc = new GlideAjax("Script Include Name");
abc.addParam("sysparm_name", 'FunctionName');
abc.addParam("sysparm_userID", newValue);
abc.getXML(Hello);
function Hello(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);
g_form.setValue("email", answer.firstName); //firstName is the obj name stored in Script include
g_form.setValue("department", answer.lastName);
g_form.setValue("manager", answer.Manager);
}
}
Client - Callable Script include:
var Autopopulate = Class.create();
Autopopulate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
myfunction: function(){
var name = {}; // to store multiple values
var usr = this.getParameter('sysparm_userID');
var tab = new GlideRecord("sys_user");
tab.addQuery("sys_id",usr);
tab.query();
if(tab.next()){
name.firstName = tab.getValue("first_name");
name.lastName = tab.getValue("last_name");
name.Manager = tab.getDisplayValue("manager");
}
return JSON.stringify(name);
},
type: 'Autopopulate'
});
In this way you can return multiple values using JSON.
Please mark it as correct if it resolved your query.