Can't access Javascript expandoObject in Javascript expression
See original GitHub issueHope all is well! I am having issue accessing my expandoObject in the javascript expression.
I have a custom Handler for Javascript expression below:
public async Task Handle(EvaluatingJavaScriptExpression notification, CancellationToken cancellationToken)
{
...get the values somehow
var values = new Database().getValues();
var obj = ToExpandoObject(values);
var context = notification.Engine;
context.SetValue("entity", obj);
var text = context.GetValue("entity"); //debug show that the expando value is stored!
}
public ExpandoObject ToExpandoObject(IEnumerable<CnsFormOps.Requests.Model.TransformedFormValues> values)
{
var eo = new ExpandoObject();
var eoColl = (ICollection<KeyValuePair<string, object>>)eo;
foreach (var kvp in values)
{
eoColl.Add(new KeyValuePair<string, dynamic>(kvp.FieldName, kvp.TransformedValue));
}
return eo;
}
In my javascript template expression, I have
JSON.stringify(Object.keys(entity).map(key => entity[key])) + " " +
JSON.stringify(entity)
the result of the string is
[] {}
I used a similar method with liquid template and it worked fine and it return the expando object just fine. I am using Elsa 1.2.2.29
I am not sure why it’s not working?? any pointers? as always really appreciate it!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Jint (.NET javascript parser) always returns ExpandoObject
This suggests to me that the underlying JavaScript method is actually returning an object rather than a string. You can use Newtonsoft.Json to ......
Read more >Working with Dynamic Objects: Beyond the Basics ...
ExpandoObjects let you dynamically add members to your object at run time -- a great way to handle scenarios where you need a...
Read more >ExpandoObject Class (System.Dynamic)
Represents an object whose members can be dynamically added and removed at run time.
Read more >ExpandoObject as a source of the Grid with Autogenerated ...
I must note that I can't promise a pivot grid will handle expandos, at least in v1, and I very much doubt it...
Read more >Making It Up as You Go Along with ExpandoObjects
You can give your users the ability to store any data they want, including stuff they make up at run time, by using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Although I am not 100% sure, I do think it might be a limitation on Jint’s side. To work around that, we might consider adding some helper functions to the script execution scope that help dealing with this sort of types.
Yeah. I just ran into the exact same thing. I also went with @sfmskywalker 's workaround. I Newtonsoft’ed my object to a JSON string in C#-land and then stored that string in my variable. As it happened, I actually wanted to output that JSON string anyway in a Write HTTP Response activity, but if I wanted bits of its object graph I could have
JSON.parse’d that string in JS.