Computed Methods with CMF

Computed Methods with CMF

Content Modeling Framework or CMF is a great tool allowing users to leverage similar functionality to Excel documents within Aras Innovator. The beauty of this is we can easily manipulate and compute properties dynamically through the use of JavaScript within these documents.

In this blog post we will be leveraging power of computed methods and properties. We will go over a use case using a simple example method to calculate a product score comparing competitor products for a company.

Setup

Our main focus will be the user input from two properties:  key relevance and market alignment. According to the user manual inputs, we will calculate a dynamic D-Score value signifying whether our product requires more attention in comparison to other products in the market. 

Before we dive into the method code, lets create our CMF structure. Note that our last blog post on CMF goes over creating the container ItemType and creating the structure if you are not familiar with this process.

1. We will create the following structure (shown below) with Key_Diff as the root element type and Prod_Values as an element type branching off Key_Diff.

2. Leave out the DScore property type for last.

3. Now we can add the DScore property type by first going to the TOC > Administration > Methods.

4. Then create a new JavaScript method called Compute D-Score (the example code is provided in the Examining the Method section of this blog).

5. Go back to the CMF structure and at the root node (Key_Diff) add another property type:

  • Dscore:
    • Data Type: Float
    • Computed Method: Compute D-Score
    • Dependent Properties: Relevance and Market Alignment

6. Make sure to add the in the views as well with the same names and mapped values all defined as property default.

CMF API

Before we get into the explanation of the function code, we should go over the CMF API briefly. CMF provides us a number of functions we can call to access data in the data structure:

1. findAncestorElement():

This function is called to get all the nodes under a root element type giving us access to any of the associated element types, property types, element bindings, and document elements. We can use this paired with the other two functions to traverse to either property/document elements or property types within the return values of this array.

2. findDescendantElements()

Using the ancestor function the descendant function allows us to loop through any child element type or element types associated.

3. getPropertyItems()

The getPropertyItems() can be used grab the property values on the element type or child element type.

4. markToUpdateValue()

This function allows user to set a new value to a property item in a cell using its ID. 

5. markToUpdateStyle()

Similar to markToUpdateValue(), one can set a style using the update style function through the ID as well.

Examining the Method Code

Note that CMF utilizes its own framework separate to that of even the IOM, but at its core is still JavaScript so we will take each line step by step within the method. Make sure to add any code to the Compute D-Score JavaScript method we created earlier. For those of us who would like to run the code first to see the intended outputs in action, I will provide the full method here:

Our goal is to take the user input relevance score and divide that by the highest market alignment score then return this value. 

1. In the first line we are grabbing the arguments array of the dependent properties we setup in the CMF structure according to the context of the root node. This means if we are creating a new Product Analysis table if we first add a Key Differentiator then it would be in context of the Relevance.

2. Using getElement() we can get access to the CMF API functions and we can call findAncestorElement() to grab the top level node of the structure.

3. Since DScore and Key Relevance are property types under the root node we can grab those values using getPropertyItem().

4. We also do some error checking to end the method if this is a new document and the user has not inputted these values yet. 

5. Continuing on we use findDescendantElements() to get an array of the property types with the product names and market alignments.

6. In order to get the user inputted market alignment values we loop through the array and use getPropertyItem().

7. We then check for the highest value in the array and use that to calculate our Dscore result.

8. Before we update the cell we use toFixed(), which is a standard javascript function, to change it to a float/round up the value and convert this to a string.

9. Finally wrapping up our last call is markToUpdateValue() that takes in the id of the cell that it is updating and sets it to the new value.

Example

Here we can see our table in action. When we add in our computed values, the relevance, and market alignments on compared products we can see the D-Score value dynamically changing. This is great for the purposes of our use case to distinguish whether our product stands up with the competition.

Conclusion

Thank you for following along with our CMF example! Through the example we can see the benefits of using computed methods to provide your organization with Excel-like functionality utilizing JavaScript. Please share your CMF projects and uses cases in the comments below.