Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting value from JsonDynamicValue in Jint #16290

Closed
hyzx86 opened this issue Jun 11, 2024 · 8 comments · Fixed by #16292 or #16298
Closed

Getting value from JsonDynamicValue in Jint #16290

hyzx86 opened this issue Jun 11, 2024 · 8 comments · Fixed by #16292 or #16298
Labels
Milestone

Comments

@hyzx86
Copy link
Contributor

hyzx86 commented Jun 11, 2024

Problem when using contentItem.Content.TestPart.TextFeildProp.Text to assign values to other objects

I use the following code in the ScriptTask of the workflow to call other queries, and I use the data of a content item to build parameters for a query

 const result =  executeQuery('myQuery', {
         prop1 : contentItem.Content.TestPart.TextFeildProp.Text
    });

With NSJ it is possible to get the actual value directly, but in the latest version of OC 2.0 additional operations must be added to get the actual value

    public class JsonTests
    {
        [Fact]
        public void ExpandoObjectSerializeTest()
        {
            dynamic expandoValue = new ExpandoObject();

            var contentItem = new ContentItem();
            contentItem.Alter<TestPart>(part =>
            {
                part.TextFeildProp = new TextField { Text = "test" };
            });

            expandoValue.stringValue = contentItem.Content.TestPart.TextFeildProp.Text;

            var jsonStr = JConvert.SerializeObject((ExpandoObject)expandoValue);
            // Actual:"{\"stringValue\":{\"JsonValue\":\"test\"}}"
            Assert.Equal("{\"stringValue\":\"strValue\"}", jsonStr);
        }

    }
    public class TestPart : ContentPart
    {
        public TextField TextFeildProp { get; set; }
    }

image

This was discussed in PR #15816, but supposedly the above scenario was not considered

Originally posted by @sebastienros in #15816 (comment)

@hyzx86
Copy link
Contributor Author

hyzx86 commented Jun 11, 2024

contentItem.Content.TestPart.TextFeildProp.Text.GetType().FullName
_> "System.Text.Json.Dynamic.JsonDynamicValue"

@hyzx86 hyzx86 changed the title contentItem.Content.MyPart.myField.Text has problems passing values to other objects. How to getting value from JsonDynamicValue type Jun 11, 2024
@hyzx86
Copy link
Contributor Author

hyzx86 commented Jun 11, 2024

Hi @gvkries , is there a recommended solution for this problem? Thanks!

@gvkries
Copy link
Contributor

gvkries commented Jun 11, 2024

You can cast Text to string I think. Also maybe try #16292 I just created, maybe it helps here as well.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Jun 11, 2024

You can cast Text to string I think. Also maybe try #16292 I just created, maybe it helps here as well.

Dude, you're so cool. 🫡

@gvkries
Copy link
Contributor

gvkries commented Jun 11, 2024

Dude, you're so cool. 🫡

🤭

hyzx86 added a commit to hyzx86/OrchardCore that referenced this issue Jun 11, 2024
@hyzx86 hyzx86 changed the title How to getting value from JsonDynamicValue type Getting value from JsonDynamicValue type problem Jun 13, 2024
@hyzx86 hyzx86 changed the title Getting value from JsonDynamicValue type problem Getting value from JsonDynamicValue problem Jun 13, 2024
@hyzx86 hyzx86 changed the title Getting value from JsonDynamicValue problem Getting value from JsonDynamicValue in Jint Jun 13, 2024
@sebastienros sebastienros added this to the 2.x milestone Jun 13, 2024
Copy link
Contributor

We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).

This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.

@sebastienros sebastienros modified the milestones: 2.x, 2.0 Jun 13, 2024
Copy link
Contributor

We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).

This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Jun 26, 2024

Hi @MikeAlhayek , pls reopen it , this issue is pending for #16298

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment