> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.pricer24.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Script syntax

# Scripts

A context object is passed to the script, which contains properties with data and methods. Some properties are read-only and cannot be changed, while others are used for writing (making changes).

There are three types of scripts:
* Product – for changing product prices, availability, tags, and properties
* Status – for changing product statuses
* Analysis – for building product data views

###  General Data
Passed to scripts of all types.

###### Data
A read-only property containing general data from the system:
* `MainCurrency` – system currency (USD, EUR, etc.)
* `Category` – a dictionary with categories, the key string with the category’s ExternalId, the value is the category data `{Id: Guid; ExternalId: string; Name: string; ParentExternalId: string; IsActive: boolean}`
* `Contractor` – a dictionary with contractors, the key string with the contractor's UnifiedName, the value is the contractor data `{ExternalId: string; Name: string; Tags: string[]}`
* `AvailabilityType` - a dictionary with availability types, the key string with the availability's UnifiedName, the value is the availability type data `{Id: Guid; Name: string; ShortName: string; UnifiedName: string; IsAvailable: boolean}`
* `ProductPriceType` – a dictionary with price types, the key string with the price type's UnifiedName, the value is the price type data `{Id: Guid; Name: string; ExtensionData: string}`
* `ContractorPriceType` – a dictionary with contractor price types, the key string with Contractor.UnifiedName-ContractorPriceType.Code, the value is the price type data `{Id: Guid; Name: string;}`
* `PriceSet` – a dictionary with price groups, the key string with the price group’s UnifiedName, the value is the price group data `{Id: Guid; Name: string; UnifiedName: string}`
* `Global` – `Dictionary <string, Dictionary<string, string>>`

###### ContractorPrices
A read-only property that contains an array with contractor prices for the current product `ReevaluationContractorPrice[]`

`ReevaluationContractorPrice` type:
* `Code` – contractor price code
* `Name` – contractor product name
* `Url` – contractor product link
* `Price` – product price
* `Currency` – currency for the product price
* `ParsedOn` – parsing date and time (DateTime)
* `Contractor` – contractor’s UnifiedName (unique short name which is set during the Contractor creation)
* `PriceSet` – price group’s UnifiedName (unique short name which is set during the PriceSet creation)

`ReevaluationContractorOffer` type:
* `Code` – contractor product code
* `Name` – contractor product name
* `Url` – contractor product link
* `IsAvail` – contractor product availability
* `ParsedOn` – parsing date and time (DateTime)
* `Contractor` – contractor’s UnifiedName (unique short name which is set during the Contractor creation)

###### Logs
A read-only property used for writing logs. Contains the `Add(string message)` method.

###### Iteration
A technical read-only property that represents the sequential number of the product during processing (e.g., first, second, third, etc.).

###### Methods

`double? ConvertPrice(double? price, string fromCurrency, string toCurrency)`
Converts the price from one currency to another.

`ReevaluationContextPricesWrapper GetPrices(Func<ReevaluationContractorPrice, bool> predicate = null)`
Retrieves contractor prices in the system currency. Optionally, it can pass a predicate for filtering.

`ReevaluationContextPricesWrapper GetPrices(string currency, Func<ReevaluationContractorPrice, bool> predicate = null)`
Retrieves contractor prices in a specified currency. Optionally, it can pass a predicate for filtering.

Type `ReevaluationContextPricesWrapper`
Contains a `ReevaluationContractorPrice[] Values` array with prices and methods: `double? Min()`, `double? Max()`, `double? Avg()`, `bool Any()`, `int Count()`.

`ReevaluationContextOffersWrapper GetOffers(Func<ReevaluationContractorOffer, bool> predicate = null)`
Retrieves contractor offers. Optionally, it can pass a predicate for filtering.

Type `ReevaluationContextOffersWrapper`
Contains a `ReevaluationContractorOffer[] Values` array with offers and methods: `bool Any()`, `int Count()`.

`decimal? Round(decimal? value, int decimals)`
`double? Round(double? value, int decimals)`
`float? Round(float? value, int decimals)`
Rounds a value to a specified number of fractional digits. (if decimals < 0 rounds to tens, hundreds, etc.)

### Product script

###### ProductOld
A read-only property with product data:
* `Price` – a dictionary with product prices, the key is the UnifiedName of the price type, the value is the price (can be null)
* `Currency` – a dictionary with product price currencies, the key is the UnifiedName of the price type, the value is the currency (can be null)
* `Property` - a dictionary with product properties, the key is the UnifiedName of the property, the value is the product property value (can be null)
* `Tag` – a dictionary with product tags, the key is the UnifiedName of the tag, the value is true or false
* `ExternalId` – the product code in your system
* `CategoryId` – category code in your system
* `Name` – product name
* `Vendor` – vendor name
* `VendorCode` – article number
* `Barcode` – barcode
* `Link` – link
* `CreationTime` – product creation date (DateTime)
* `Availability` – UnifiedName of availability
* `Catalog` – UnifiedName of the catalog
* `IsActive` – product status (true/false)

###### Product
A property for writing:
* `Availability` – UnifiedName of availability type
* `Price` – a dictionary with product prices, the key UnifiedName of the price type, value = price (can be null).
* `Currency` – a dictionary with product price currencies, the key UnifiedName of the price type; value = currency (can be null)
* `Tag` – a dictionary with product tags, the key UnifiedName of the tag, value = true/false)
* `Property` – a dictionary with product properties, the key UnifiedName of the property, value = property value (string)


### Status script

###### ProductOld
A read-only property with product data, the same as in the Product script.

###### Product
A property for writing:
* `IsActive` – true/false

### Analysis
Consists of two scripts: columns and data. The script for calculating columns is executed once before the script for generating data for each product in these columns.

###### Columns
* `Columns` – property contains a method for adding a column:
`Add(string dataField, string caption, int width, string alignment = null, string band = null, bool isFixed = false)`

###### Data
* `ProductOld` – a read-only property with product data, the same as in the Product script
* `Cell` – a dictionary for filling data in cells, the key *DataField* column’s and the value is a *CellData* object

`CellData` type contains properties:
* `Text` – text in the cell
* `ToolTip` – tooltip on hover
* `Background` – background color
* `Color` – text color
* `IconId` – icon
* `IconColor` – icon color
* `Href` – link (if filled, the text will be displayed as a link)
* `Bold` – true/false
* `Italic` – true/false
* `TextDecoration` – underline/line-through