Add ClearScript Service

This forum allows users to post and respond to "How Do I Do ....." questions. The information contained in this forum has not been validated by K-Rise Systems and, as such, K-Rise Systems cannot guarantee the accuracy of the information.
JefferyD
Posts: 177
Joined: August 31st, 2021, 11:37 am
Contact:

Add ClearScript Service

Unread post by JefferyD »

There is a library called "ClearScript" that allows server-side JavaScript that I would love to see implemented as a new service. It also seems to run in a very controlled environment that cannot access anything outside of what is defined in the JavaScript code unless it is specifically given access to it, similar to how little access XSLT logic has from within EASYProcess. Some related reading.

Idea for how the service parameters could be structured:

Code: Select all

<CreateServiceNodeFromScript>
    <Variables>
        <Variable IsArray="True" Index="1">
            <Name>StrVar</Name>
            <Type>String</Type>
            <Data>
                <!-- (Type="String") XSLT that evaluates to a string -->
                <xsl:value-of select="WorkData/GetText/Output/Result/Text"/>
            </Data>
        </Variable>
        <Variable IsArray="True" Index="2">
            <Name>NodeVar</Name>
            <Type>NodePath</Type>
            <Data>
                <!-- (Type="NodePath") A node path that results in an array of JSON objects converted from the XML of each node -->
                WorkData/GetItems/Output/Result/Item
            </Data>
        </Variable>
    </Variables>
    <Script>
        <!-- Javascript goes here where each variable name is referencable.  -->
        let message, success, priceTotal;
        if (strVar.length > 10) {
            message = strVar.substring(0,10);
            success = true;
        }
        else {
            message = "Input must be 10+ characters";
            success = false;
        }

        <!-- NodeVar is an array of JSON objects converted from "Item" XML -->
        priceTotal = 0;
        NodeVar.forEach((Item) => {
            if(Item.Price > 0) {
                Item["TotalPrice"] = Item.Price * Item.Quantity
                priceTotal += Item.Price * Item.Quantity;
            }
        });

        <!-- if returning single value, then Result of service just the value -->
        <!-- if returning JSON object, then Result of service is XML converted from returned JSON  -->
        return {
            "Success": success,
            "Message": message,
            "Items": {
                "TotalPrice": priceTotal,
                "ItemList": NodeVar
            }
        }
    </Script>
</CreateServiceNodeFromScript>
image.png
word count: 254

Tags:
Post Reply