# F. Espacio de Nombres (Functions)

#### Abrir Recursos

```javascript
F.OpenReport(reportId)          // Opens a report by GUID
F.OpenForm(sectionId)           // Opens a form section by GUID
F.OpenDynamicDocument(apiId)    // Opens an API function by GUID
```

***

### Tablas de Datos

Crear y manipular tablas de datos en memoria.

#### Crear Tablas

```javascript
var tableId = F.DataTable_New()              // Creates a new table
F.DataTable_AddRow(tableId)                  // Adds a new row
```

#### Establecer Valores

```javascript
F.DataTable_SetValue(tableId, "column", "value")           // Sets text value
F.DataTable_SetValueInt(tableId, "column", 42)             // Sets integer
F.DataTable_SetValueNum(tableId, "column", 3.14)           // Sets decimal number
F.DataTable_SetValueDate(tableId, "column", dateValue)     // Sets date
F.DataTable_SetValueBool(tableId, "column", true)          // Sets boolean
F.DataTable_SetValueMoney(tableId, "column", 99.99)        // Sets currency
F.DataTable_SetValuePercentage(tableId, "column", 0.25)    // Sets percentage
```

#### Exportar Tablas

```javascript
F.DataTable_Build(tableId, "JSON")          // Outputs as JSON, HTML, CSV, or XML
F.DataTable_Export(tableId, "CSV")          // Exports to file (terminal only)
```

***

### Listas de Datos

Cargar y filtrar datos desde informes o secciones.

```javascript
F.DataListLoad(reportId, pageNum, resultsPerPage)
F.DataListLoadAddFilter(reportId, field, "*")        // Operators: '=', '<>', '>', '<', '>=', '<='
F.DataListLoadSetOrder(reportId, field, ascending)
F.ProcessDataList_Ini("keyword")                     // Start processing
F.ProcessDataList_End()                              // End processing
```

#### Información de Listas

```javascript
F.DataListCountResults(reportId)            // Total results
F.DataListCountPages(reportId)              // Total pages
F.DataListCurrentPage(reportId)             // Current page number
```

***

### Fecha y Hora

#### Extraer Componentes

```javascript
F.Year(date)                    // Returns year
F.Month(date)                   // Returns month (1-12)
F.Day(date)                     // Returns day
F.Hour(time)                    // Returns hour
F.Minute(time)                  // Returns minute
F.DayOfWeek(date)               // Returns 1=Monday, 7=Sunday
```

#### Construir Fechas

```javascript
F.BuildDate(2024, 12, 25)                          // Creates a date
F.BuildTime(14, 30, 0)                             // Creates a time (2:30 PM)
F.BuildDateTime(2024, 12, 25, 14, 30)              // Creates datetime
```

#### Aritmética de Fechas

```javascript
F.Date_AddDays(date, 7)                    // Add 7 days
F.Date_AddMonths(date, 2)                  // Add 2 months
F.Date_AddYears(date, 1)                   // Add 1 year
F.DateTime_AddHours(datetime, 3)           // Add 3 hours
F.DateTime_AddMinutes(datetime, 30)        // Add 30 minutes
```

#### Rangos de Fechas

```javascript
F.Date_GoToStartOfMonth(date)              // First day of month
F.Date_GoToEndOfMonth(date)                // Last day of month
F.Date_GoToStartYear(date)                 // January 1st
F.Date_GoToStartWeekMonday(date)           // Monday of current week
```

#### Calcular Diferencias

```javascript
F.DaysDifferenceBetweenDates(date1, date2)
F.MinutesDifferenceBetweenDates(date1, date2)
F.CalculateAge(birthdate, currentDate)              // Age in years
```

***

### Operaciones Numéricas

#### Redondeo y Conversión

```javascript
F.Round(3.14159, 2)             // Returns 3.14
F.Ceiling(2.1)                  // Returns 3
F.Floor(2.9)                    // Returns 2
F.Truncate(3.7)                 // Returns 3 (integer part)
F.Cast_NumToInt(5.8)            // Nearest integer
```

#### Mínimo/Máximo

```javascript
F.Max_Num(10, 20)               // Returns 20
F.Min_Num(10, 20)               // Returns 10
F.Max_Int(5, 15)                // Returns 15
F.Min_Int(5, 15)                // Returns 5
```

#### Operaciones con Porcentajes

```javascript
F.PercentageIncrease(100, 10)              // 100 + 10% = 110
F.PercentageDecrease(100, 10)              // 100 - 10% = 90
F.PercentageReverse(110, 10)               // Remove 10% from 110
F.PercentageDifference(50, 75)             // Percentage difference
```

#### Conversión de Signo

```javascript
F.EnsurePositive(-5)            // Returns 5
F.EnsureNegative(5)             // Returns -5
```

***

### Operaciones de Texto

#### Operaciones Básicas

```javascript
F.Length("hello")                          // Returns 5
F.ToUppers("hello")                        // Returns "HELLO"
F.ToLower("HELLO")                         // Returns "hello"
F.Concat("Hello", " World")                // Returns "Hello World"
```

#### Búsqueda

```javascript
F.Contains("hello world", "world")         // Returns true
F.StartsWith("hello", "hel")               // Returns true
F.EndsWith("hello", "lo")                  // Returns true
```

#### Manipulación

```javascript
F.Substring("hello", 1, 3)                 // Returns "hel" (1-based index)
F.Replace("hello", "l", "L")               // Returns "heLLo"
F.RemoveStart("hello", 2)                  // Returns "llo"
F.RemoveEnd("hello", 2)                    // Returns "hel"
F.PadLeft("5", 3, "0", false)              // Returns "005"
F.PadRight("5", 3, "0", false)             // Returns "500"
```

#### Validación

```javascript
F.IsNumeric("123")              // Returns true
F.IsInteger("123")              // Returns true
```

***

### JSON y Diccionarios

#### Diccionarios de Texto

```javascript
var dict = F.DicT_New()
F.DicT_Add(dict, "name", "John")
F.DicT_Get(dict, "name", "")               // Returns "John"
F.DicT_ContainsKey(dict, "name")           // Returns true
F.DicT_ToJson(dict)                        // Convert to JSON
```

#### Diccionarios Numéricos

```javascript
var dict = F.DicN_New()
F.DicN_Add(dict, "age", 25)
F.DicN_Get(dict, "age", 0)                 // Returns 25
F.DicN_Count(dict)                         // Number of items
```

***

### Gráficos

```javascript
var chartId = F.Chart_New("Sales Report")
F.Chart_AddSerie(chartId, "Q1", "#3498db", "#2c3e50")
F.Chart_AddValue(chartId, "January", 1000, "#e74c3c", "#c0392b")
F.Chart_AddValue(chartId, "February", 1500, "#2ecc71", "#27ae60")
var html = F.Chart_ToHTML(chartId, chartType, 800, 400)
```

***

### Utilidades

#### Formateo

```javascript
F.FormatMoney(1234.56)                     // Currency format: $1,234.56
F.FormatNumeric(1234.56)                   // Numeric format: 1,234.56
F.FormatPercentage(0.25)                   // Percentage format: 25%
```

#### Codificación

```javascript
F.URLEncode("hello world")                 // URL-safe encoding
F.JSEncode("text with 'quotes'")           // JavaScript-safe encoding
```

#### Otros

```javascript
F.NewGuid()                                // Generates random GUID
F.NewPassword(12, true)                    // 12-char password with special chars
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.dinaup.com/desarrollo/flex/dinascript/f.-espacio-de-nombres-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
