- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2017 12:40 AM
Script Include :
var HelloWorld = Class.create();
HelloWorld .prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
Approve: function(a) {
return "The Server Says Hello " + this.getParameter('sysparm_user_name') + "!" ;
}
});
client Side OnLoad:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name','Approve');
ga.addParam('sysparm_user_name',"Bob");
ga.getXMLWait();
alert(ga.getAnswer());
}
i would like to set values
state=3,category=software, short_description=''welcome to scripting" i want to write this code in script include and i would like to call that server code when i load a form in client side, this values should set into field.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2017 04:23 AM
Hi,
The client script code is using parse() function and I had provided a different one. You can ignore the warning message on script include, Please copy and replace these scripts exactly and check if it is working. Also see if alerts are prompted.
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name','Approve');
ga.addParam('sysparm_user_name',"Bob");
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.evalJSON(); //Transform the JSON string to an object
alert(answer);
alert(answer.short_description);
g_form.setValue("short_description", answer.short_description);
g_form.setValue("category", answer.category);
g_form.setValue("state", answer.state);
}
}
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
Approve: function(a) {
var obj = {short_description: "welcome to scripting", state: 3, category: "software"};
var data = new JSON().encode(obj); //JSON formatted string
return data;
}
});
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2017 03:48 AM
Have you checked the script include as client callable?
Can you please provide the full screenshots of both your script include and client script?
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2017 03:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2017 04:23 AM
Hi,
The client script code is using parse() function and I had provided a different one. You can ignore the warning message on script include, Please copy and replace these scripts exactly and check if it is working. Also see if alerts are prompted.
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name','Approve');
ga.addParam('sysparm_user_name',"Bob");
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.evalJSON(); //Transform the JSON string to an object
alert(answer);
alert(answer.short_description);
g_form.setValue("short_description", answer.short_description);
g_form.setValue("category", answer.category);
g_form.setValue("state", answer.state);
}
}
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
Approve: function(a) {
var obj = {short_description: "welcome to scripting", state: 3, category: "software"};
var data = new JSON().encode(obj); //JSON formatted string
return data;
}
});
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2017 04:53 AM
thanks, i am very glad with your code....
its working.....thnq soooo much.
i have one query ..plse
can we add this calling message ''Bob''
i mean display message as "The Server Says Hello Bob", after that values need to display there places..
onLoad:
ga.addParam('sysparm_name','Approve');
ga.addParam('sysparm_user_name',"Bob");
Script Include
return "The Server Says Hello " + this.getParameter('sysparm_user_name') + "!"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2017 05:01 AM
Please added the bold lines to your code at both client script and script include and check if it works
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name','Approve');
ga.addParam('sysparm_user_name',"Bob");
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.evalJSON(); //Transform the JSON string to an object
alert(answer.message);
g_form.setValue("short_description", answer.short_description);
g_form.setValue("category", answer.category);
g_form.setValue("state", answer.state);
}
}
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
Approve: function(a) {
var obj = {short_description: "welcome to scripting", state: 3, category: "software", message: "The Server Says Hello " + this.getParameter('sysparm_user_name') + "!"};
var data = new JSON().encode(obj); //JSON formatted string
return data;
}
});
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response