Skip to content

Latest commit

 

History

History
76 lines (55 loc) · 5.18 KB

advanced-scripting.md

File metadata and controls

76 lines (55 loc) · 5.18 KB
description cover coverY
[Work in progress]
0

Advanced Scripting

Advanced Rules are more difficult to use, but they are much more powerful than the other rules.

User scriptable rules (JavaScript) have access to 4 parameters, instead of just 1. The rules that fall into this category are:

  • Text Manipulation (import / export)
  • Text Evaluation (display)
  • Export Manipulation (export only)

The parameters available to these rules are listed below:

ParameterDescriptionNote
sThe current string value from the sourceCan be modified by previous rule
rowDataThe entire row's data (all the cell values, modifications, differences, etc.)Cannot be modified, read-only
pThe pass / block valueCannot be modified, read-only
pmThe property mapping objectContains additional options such as "Is it read-only"

typical rules only have access to the string value s which is passed to it. In the table listed above are the data to which special rules listed on this page has access to. It allows for much greater scripting capability.

When the rule is an export or import rule, the result of a rule must always be a string or a representation of a string such as a JavaScript object (JSON) which has been serialized. If it does not return a value you may experience unexpected results in the UI, possibly even instability (BOM view not rendering) in attempting to render client side BOMs.

When the rule is an evaluation rule, the result (which must only be returned for errors or warnings), must be an object containing a 'message' key, e.g.

{ 'message' : 'if the rule fails show this text in the tooltip' }

{% hint style="info" %} Should you happen to break your BOM view using these scripts, simply disable the rule. {% endhint %}

ParamDescription
sThe current string value in the cell (changes with each successive import rule or export rule (if there are any)
rowDataThe rowData object (more detail below **)
pThe pass / block value, does not change
pmThe Property Mapping's object. Does not change. (** more detail below)

** The rowData value is a special value. It contains, but is not limited to, the following key/values:

Key nameDescription of the value
isAssemblyRowA bool value indicating if the current row value is an assembly row (contains children according to the source)
componentNameThe primary identifier of each row - typically the name of the component
componentPathArrayThe path of each component. So if you have assembly A1, with Part P1, then this value will be [ 'A1', 'P1' ]
cells

The row values for the entire row. A typical row object might look something like this (notice the nested `cells` key):

{
  "isAssemblyRow" : false,
  "componentName" : "Part 1",
  "componentPathArray" : [ "A1", "Part 1"],
  "cells" : {
     "partNumber" : "P1",
     "description" : "Side plate",
     "revision" : "A"
     "material" : "steel",
     "qty" : 1,
  }
} 
modifications
{
  "isAssemblyRow" : false,
  "componentName" : "Part 1",
  "componentPathArray" : [ "A1", "Part 1"],
  "modifications" : {
     "partNumber" : "P1-PN",
     "description" : "Side Plate",
     "material" : "Steel",
  }
} 
primaryExportDataobject containing the final set of data to send to the Primary Source. This is the final set of values to be sent.
secondaryExportDataobject containing the final set of data to send to the Secondary Source. This is the final set of values to be sent

** The pmvalue is a special value. It contains, but is not limited to, the following key/values:

Key name Description of the value
isReadOnly Whether the admin has selected this property as editable
isVisible Whether the admin has selected this property as visible by default
shouldUpdatePrimaryDatasource Whether to update the Primary Source
shouldUpdateSecondaryDatasource Whether to update the Secondary Source