
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2018 08:04 PM
I am developing a custom widget on service portal and I have all the logic coded out on the Server Script. Now I realized that i can reuse some of the logic and want it to be reusable in the future for other widgets.
How can I set up a script include then pass a variable from server script to that script include and have the script include process that variable and return a value?
SAMPLE:
//OLD SERVER SCRIPT CODE:
var x = '0';
//The code below is a sample of what I want to be reusable in other widgets through script include
if (x == '0'){
// do nothing
} else {
//do this one
x = x + 1;
}
data.msg = x;
//NEW SERVER SCRIPT CODE:
var x = '0';
data.msg = new myScript().test(x);
I tried above and the variable x seems to be not being processed by script include.
SCRIPT INCLUDE: (updated the test: function(x) part as suggested)
var myScript = Class.create();
myScript.prototype = {
initialize: function() {
},
test: function(x) {
if(x==0){
return true;
} else {
return false;
}
},
isPublic: function() {
return true;
},
type: 'myScript'
};
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2018 12:25 AM
can you update the test function like below and check :
test: function (x)
{
if(x==0)
{
return true;
}
else {
return false;
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2018 12:43 AM
Hi,
in your script include remove test in test definition as :
...
test:function(x){
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2018 02:36 AM
Again I'm afraid your test definition isn't good.
You have
test:function test(x)
and you should have
test:function(x)
Regards,
PY

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2018 02:44 AM
Already changed that part as suggested but still it doesn't work:
var myScript = Class.create();
myScript.prototype = {
initialize: function() {
},
test: function(x) {
if(x==0){
return true;
} else {
return false;
}
},
isPublic: function() {
return true;
},
type: 'myScript'
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2018 02:58 AM
Hi,
Did you get output from above code?
please try
var x=10 instead of var x="10";