GlideScopedEvaluator not passing Javascript object as variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2018 10:00 AM
I am unable to pass a Javascript object as an argument to a script called via GlideScopedEvaluator. I just tried the following on a dev instance.
//script table contains name and script fields
var script_gr = new GlideRecord('x_62845_test_script');
script_gr.get('name','test_script');
var args = {
"testObj":{"var1":1,"var2":2},
"test":"asdf"
}
var ge = new GlideScopedEvaluator();
ge.evaluateScript(script_gr,'script',args);
The script contained in the record that the GlideScopedEvaluator is using is
(function(testObj, test){
gs.info("Object was " + JSON.stringify(testObj));
gs.info("String was " + test);
})(testObj, test);
The results of the script are:
ScopedRhinoObjectWrapper: not a wrappable type: java.util.HashMap
x_62845_test: Object was null
x_62845_test: String was asdf
Is this a bug or am I doing something wrong?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2018 11:39 AM
The answer was to use the putVariable method of GlideScopedEvaluator to pass in the value. It worked like a charm after that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2018 07:30 AM
hi can you please paste code after fix we are facing same issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2018 10:21 AM
So I can't post the exact code, but here is a snippet that explains what I mean
var gr = new GlideRecord('table_that_has_script_field');
var ge = new GlideScopedEvaluator();
ge.putVariable('variable_name_here',yourObject);
ge.evaluateScript(gr,'script_field_name');