Page tree
Skip to end of metadata
Go to start of metadata

Challenge

You want to use a script during mapping of CAD values from CAD to SAP characteristics.

Solution

In applications\<cad>\customize\config\attributes-to-sap.xml you can define a script (convert.js) when mapping a CAD attribute (CAD_PROPERTY1 to a SAP characteristic (SAP_CHAR1).

attributes-to-sap.xml
<DIR_CLS class="AUTOCADCLASS" classtype="017" characteristic="SAP_CHAR1" transfer_empty_value="true">
  <SCRIPT name="convert.js">
     <APPL_ATTRIBUTE name="CAD_PROPERTY1" />
  </SCRIPT>
</DIR_CLS>


In folder <ECTR configuration>\customize\scripts\attributes you create a script-file convert.js.
Here’s an example:

convert.js
// this script converts the string representing a number in exponential format
// like 3.633432511522E+09 or 3,633432511522E+09 into usual number format 3633432511.522
// input with "e" but which not represents a number in exponential format will produce "NaN" - not a number
// other input values will not be converted

value = ""; // global variable "value" as return value

if(argv.length>0){
  value = argv[0] // first assign unconverted value, for the case it is not in exponential form
  // do the right conversion
  if(value.contains("E") || value.contains("e")){
    var neutral = value.replace(",",".") //only needed if your input value uses , as decimal separator instead of .
    value = Number(neutral)
  }
}



  • No labels