You may have data stored as an array or as a custom type in your configurator, and want to pass that data into the CAD extension for use there. You can pass complex data –- beyond simple text and numbers -- to the CAD Extension through a technique called serialization.
In a nutshell, you serialize your complex data into a stream of text that can pass easily from Epicor CPQ into the extension. Once there, the data is deserialized back into its original complex form. The process of converting data into this stream of text and back out again is performed by a "serializer" – a library of code designed to do this work. You don't have to do it yourself! All you have to do is add the serializer to your extension project.
Adding JSON Serializer/Deserializer to References in CAD Extension
-
In your VB project, Go to ‘Manage NuGet Packages for Solution'
-
In the search bar type Json, choose ‘Newtonsoft.Json’, and install it
-
You should now see 'Newtonsoft.Json' in your references:
Running CAD Extensions with the Json Deserializer
- In order to use the deserializer, it is also necessary to place a copy of the newtonsoft.json.dll in the CAD Extensions - > Rules Folder.
- You can copy it from here: C:\Users\<username>\AppData\Roaming\Epicor3\Epicor CPQ Desktop Tools
-
And paste it here: C:\Epicor CPQ\Extensions\Rules
Serializing Data in Configurator to pass to CAD Extension
So you've prepared your project and your CAD workstation to use serialized data. To use serialized data, first create a complex object within your configurator, and store its data in a serialized form. Here's an example of serialized data being created in Epicor CPQ.
-
In this example, let's say our configurator uses a custom type called "DrawingView", and a function to create an array of DrawingViews to be passed to the CAD Extension.
The specifics of the "GetDrawingViews" function is not important: it uses business logic to create an array of zero or more DrawingView objects.
-
This complex data from the GetDrawingViews function must be stored in a field, so the CAD Extension can see it and use it. So, in this example, we create a text field called ‘(To Drawing) Drawing Views’ and placed it
in a hidden page.
-
And in a value rule, we call the function that generates our complex data, serialize the data into a stream of text, and store that text in the hidden field.
-
When we run the configurator, we can see the text representing the serialized array of DrawingView objects in the field:
The complex data is ready to be used by the CAD Extension.
Deserializing Data in the CAD Extension
- In the CAD Extension, grab the data from the ‘(To Drawing) Drawing Views’ field and place it in a variable (m_myDrawingViewList).
-
Create a class exactly like the type defined above in the Configurator. The Epicor CPQ type and the Extension class must match.
-
In the Subroutine in which you want to use this data, deserialize the data from the configurator and put it into an Array of Drawing Views.
- You can now access this data the same way you would have in the configurator.