Los elementos del catálogo se almacenan en la tabla Elemento del catálogo (mspcat_applications) . Esta tabla tiene una columna mspcat_TPSID(Identificación del artículo del catálogo) que almacena un valor de cadena único que puede utilizar para referirse a un artículo del catálogo.
Por ejemplo, supongamos que la siguiente tabla representa las versiones disponibles del artículo del catálogo: MyCatalogItem
Los siguientes valores del parámetro ID de elemento de catálogo tienen comportamientos diferentes:
Utilice el comando pac catalog install para instalar elementos del catálogo.
En este ejemplo, está conectado al EnvironmentWithCatalog.
Utilice el parámetro -cid para especificar el ID del elemento de catálogo y -te para especificar el entorno en el que instalar el elemento de catálogo.
También puede especificar una versión específica.
pac catalog install `
-cid ContosoConferencesCustomConnector `
-te https://<org to install item>.crm.dynamics.com/
Connected as user@domain
Connected to... EnvironmentWithCatalog
Tracking ID for this installation is 9cc47262-2f33-ef11-8409-6045bdd3aec3
El ID de seguimiento devuelto es la clave principal del registro Historial de instalación (mspcat_InstallHistory) que puede revisar para ver si la instalación se ha realizado correctamente.
¿Qué es Microsoft Power Platform CLI?
Hay dos mensajes que puedes usar para instalar elementos del catálogo: mspcat_InstallCatalogItemByCID y mspcat_InstallCatalogItem. La mayor parte del tiempo debe usar el método mspcat_InstallCatalogItemByCID.
mspcat_Instalar elemento de catálogo por solicitud CID
Utilice este mensaje con el valor de la columna mspcat_TPSID (Identificación del artículo del catálogo).
Puede especificar una versión concreta. PAC CLI y la aplicación utilizan este mensaje.
El siguiente método estático InstallCatalogItemByCIDExample muestra cómo invocar este mensaje utilizando las clases en tiempo de compilación generadas para ello mediante pac modelbuilder build.
/// <summary>
/// Demonstrates how to install a catalog item in Power Platform.
/// </summary>
/// <param name="service">The authenticated IOrganizationService instance.</param>
/// <param name="catalogItemId">The mspcat_TPSID value of the catalog item, optionally with @version</param>
/// <param name="deployToOrgUrl">The URL of the environment to install the item in.</param>
/// <param name="settings">The settings to apply (optional)</param>
/// <returns>A reference to the install history so you can check the status</returns>
static EntityReference InstallCatalogItemByCIDExample(IOrganizationService service,
string catalogItemId,
Uri deployToOrgUrl,
string? settings = null)
{
var request = new mspcat_InstallCatalogItemByCIDRequest
{
CID = catalogItemId,
DeployToOrganizationUrl = deployToOrgUrl.ToString(),
};
if (string.IsNullOrEmpty(settings))
{
request.Settings = settings;
}
var response = (mspcat_InstallCatalogItemByCIDResponse)service.Execute(request);
return response.InstallHistoryReferance;
}
Ejemplo de uso
El siguiente ejemplo muestra el uso del método estático. InstallCatalogItemByCIDExample
EntityReference installHistoryReference = InstallCatalogItemByCIDExample(
service: service,
catalogItemId: "MyCatalogItem@1.0.0.0",
deployToOrgUrl: new Uri("https://<org to install item>.crm.dynamics.com/"));
Console.WriteLine(installHistoryReference.Id);
Parámetros de configuración
Los ajustes pasados a la solicitud como una cadena que representa la propiedad IImportExtensions2.RuntimeSettings donde los ajustes son un Dictionary<String,Object> serializado y el carácter de barra vertical es un delimitador entre los ajustes. Si settings representa el diccionario de ajustes, serialice el ajuste utilizando un código como este:
string serializedSettings = string.Join("|", settings.Select(kvp => $"{kvp.Key}:{kvp.Value}"));
mspcat_Solicitud de elemento de catálogo de instalación
Este mensaje se proporciona a título informativo y, en general, no debería utilizarlo. Utilice mspcat_InstallCatalogItemByCIDRequest para operaciones normales. Este mensaje es utilizado por el comando pac catalog install de la CLI del PAC cuando se especifica el parámetro opcional --target-version.
Utilice este mensaje cuando tenga una referencia al elemento del catálogo que desea instalar o desee incluir una referencia a un registro de paquete específico para instalar relacionado con el elemento del catálogo.
El siguiente método estático InstallCatalogItemExample muestra cómo invocar este mensaje utilizando las clases en tiempo de compilación generadas para ello mediante pac modelbuilder build.
/// <summary>
/// Demonstrates how to install a catalog item in Power Platform.
/// </summary>
/// <param name="service">The authenticated IOrganizationService instance.</param>
/// <param name="target">Reference to the catalog item to install</param>
/// <param name="deployToOrgUrl">The URL of the environment to install the item in.</param>
/// <param name="settings">The settings to apply (optional)</param>
/// <param name="packageId">The packageId to apply (optional)</param>
/// <returns>A reference to the install history so you can check the status</returns>
static EntityReference InstallCatalogItemExample(IOrganizationService service,
EntityReference target,
Uri deployToOrgUrl,
string? settings = null,
Guid? packageId = null)
{
if (target.LogicalName != "mspcat_applications")
{
throw new Exception("target parameter must be a reference to a Catalog Item (mspcat_applications) record");
}
var request = new mspcat_InstallCatalogItemRequest
{
Target = target,
DeployToOrganizationUrl = deployToOrgUrl.ToString(),
};
if (packageId.HasValue)
{
request.PackageId = packageId.Value;
}
if (string.IsNullOrEmpty(settings))
{
request.Settings = settings;
}
var response = (mspcat_InstallCatalogItemResponse)service.Execute(request);
return response.InstallHistoryReferance;
}
Las configuraciones pasadas a este mensaje son las mismas que se utilizan para mspcat_InstallCatalogItemByCIDRequest. Consulte Parámetro de configuración
Utilice el SDK de Dataverse para .NET
Generar clases de enlace en tiempo de compilación para SDK para .NET
Hay dos operaciones que puede utilizar para instalar elementos del catálogo: mspcat_InstallCatalogItemByCID acción y mspcat_InstallCatalogItem función. La mayor parte del tiempo debe usar la acción mspcat_InstallCatalogItemByCID.
Acción mspcat_InstallCatalogItemByCID
La siguiente función de PowerShell describe cómo utilizar la acción. Install-CatalogItemByCIDmspcat_InstallCatalogItemByCID Con esta acción, puede especificar una versión específica para instalar.
Esta función depende de los valores variables globales $baseURI y $baseHeaders establecidos mediante la función de ejemplo Connect, tal y como se describe en Crear una función Connect.
<#
.SYNOPSIS
Installs a catalog item to a specified organization URL using its catalog item ID (CID).
.DESCRIPTION
The `Install-CatalogItemByCID` function installs a catalog item to a specified organization URL using the Microsoft Dynamics CRM API.
It constructs the appropriate request body with mandatory and optional parameters and sends a POST request to the API.
.PARAMETER catalogItemId
The ID of the catalog item to be installed. This parameter is mandatory.
.PARAMETER deployToOrgUrl
The URL of the organization where the catalog item will be deployed. This parameter is mandatory.
.PARAMETER settings
Optional settings for the installation. This parameter is optional.
.PARAMETER skipSendToCatalogService
A boolean flag indicating whether to skip sending to the catalog service. This parameter is optional.
.RETURNVALUE
[string] The `mspcat_installhistoryid` value from the API response, which is the ID of the installation history record.
.EXAMPLE
Install-CatalogItemByCID `
-catalogItemId 'ContosoConferencesCustomConnector' `
-deployToOrgUrl 'https://<org to install item>.crm.dynamics.com/' `
-settings = 'Key=Value|Key1=Value1'
#>
function Install-CatalogItemByCID {
param (
[Parameter(Mandatory)]
[string]
$catalogItemId,
[Parameter(Mandatory)]
[string]
$deployToOrgUrl,
[string]
$settings,
[bool]
$skipSendToCatalogService
)
$body = @{
CID = $catalogItemId
DeployToOrganizationUrl = $deployToOrgUrl
}
if ($settings) {
$body.Add('Settings', $settings)
}
if ($skipSendToCatalogService) {
$body.Add('SkipSendToCatalogService', $skipSendToCatalogService)
}
$postHeaders = $baseHeaders.Clone()
$postHeaders.Add('Content-Type', 'application/json')
$results = Invoke-RestMethod `
-Method Post `
-Uri $baseURI"mspcat_InstallCatalogItemByCID" `
-Headers $postHeaders `
-Body ($body | ConvertTo-Json)
return $results.mspcat_installhistoryid
}
Función mspcat_InstallCatalogItem
La siguiente función de PowerShell describe cómo utilizar la función. Install-CatalogItemmspcat_InstallCatalogItem Esta función depende de los valores variables globales $baseURI y $baseHeaders establecidos mediante la función de ejemplo Connect, tal y como se describe en Crear una función Connect.
<#
.SYNOPSIS
Installs a catalog item to a specified organization URL.
.DESCRIPTION
The `Install-CatalogItem` function installs a catalog item to a specified organization URL using the Microsoft Dynamics CRM API.
It constructs the appropriate URL with mandatory and optional parameters and sends a GET request to the API.
.PARAMETER catalogItemId
The GUID ID of the catalog item to be installed. This parameter is mandatory.
.PARAMETER deployToOrgUrl
The URL of the organization where the catalog item will be deployed. This parameter is mandatory.
.PARAMETER settings
Optional settings for the installation. This parameter is optional.
.PARAMETER skipSendToCatalogService
A boolean flag indicating whether to skip sending to the catalog service. This parameter is optional.
.RETURNVALUE
Returns the `mspcat_installhistoryid` value from the API response, which is the ID of the installation history record.
.EXAMPLE
Install-CatalogItem `
-catalogItemId df32c7c8-2137-ef11-8409-6045bdd3aec3 `
-deployToOrgUrl 'https://<org to install item>.crm.dynamics.com/' `
-settings = 'Key=Value|Key1=Value1'
#>
function Install-CatalogItem {
param (
[Parameter(Mandatory)]
[string]
$catalogItemId,
[Parameter(Mandatory)]
[string]
$deployToOrgUrl,
[string]
$settings,
[bool]
$skipSendToCatalogService
)
# This is a bound function that requires a GUID identifier for the
# catalog item
$url = $baseURI + 'mspcat_applicationses(' + $catalogItemId + ')'
$url += '/Microsoft.Dynamics.CRM.mspcat_InstallCatalogItem'
$url += '(DeployToOrganizationUrl=@deployToOrgUrl'
# Set optional parameters
if ($settings) {
$url += ',Settings=@settings'
}
if ($skipSendToCatalogService) {
$url += ',SkipSendToCatalogService=@skipSendToCatalogService'
}
$url += ")?@deployToOrgUrl='" + $deployToOrgUrl +"'"
# Set optional parameter values
if ($settings) {
$url += "&@settings='" + $settings +"'"
}
if ($skipSendToCatalogService) {
$url += '&@skipSendToCatalogService=' + $skipSendToCatalogService
}
$results = Invoke-RestMethod `
-Method Get `
-Uri $url `
-Headers $baseHeaders
return $results.mspcat_installhistoryid
}
Usar la API web de Microsoft Dataverse
Use PowerShell y Visual Studio Code con la API web de Dataverse
Utilice el comando pac catalog status para comprobar el estado de las instalaciones del catálogo.
pac catalog status --tracking-id 0e6b119d-80f3-ed11-8849-000d3a0a2d9d --type Install
Connected to... TestCatalog
Connected as user@domain
Status of the Install request: Requested
¿Qué es Microsoft Power Platform CLI?
El siguiente método estático GetInstallSuccess comprueba el estado del registro Historial de instalación (mspcat_InstallHistory) para determinar si la instalación se ha realizado correctamente.
/// <summary>
/// Polls the install success of a catalog item
/// </summary>
/// <param name="service">The authenticated IOrganizationService instance.</param>
/// <param name="id">The mspcat_installhistoryid value</param>
/// <param name="intervalInSeconds">The number of seconds of interval</param>
/// <returns>Whether the installation succeeded</returns>
/// <exception cref="Exception">The polling is limited to 10 attempts.</exception>
static bool GetInstallSuccess(IOrganizationService service, Guid id, int intervalInSeconds = 60) {
int maxAttempts = 10;
int attempts = 0;
while (attempts < maxAttempts)
{
attempts++;
Entity currentValue = service.Retrieve("mspcat_installhistory", id, new ColumnSet("statecode", "statuscode"));
// Wait until the state of the operation is inactive
if (currentValue.GetAttributeValue<OptionSetValue>("statecode").Value.Equals(1))
{
if (currentValue.GetAttributeValue<OptionSetValue>("statuscode").Value.Equals(526430003))
{
// When the statuscode values is 'Completed'
return true;
}
// Any other status code: 'Inactive' or 'Failed'.
return false;
}
Thread.Sleep(intervalInSeconds * 1000);
}
throw new Exception("Maximum number of polling attempts exceeded.");
}
Utilice el SDK de Dataverse para .NET
La siguiente función Get-InstallSuccess comprueba el estado del registro Historial de instalación (mspcat_InstallHistory) para determinar si la instalación se ha realizado correctamente. Esta función depende de la función Get-Record, descrita en Crear funciones de operaciones de tabla.
<#
.SYNOPSIS
Polls the install success of a catalog item.
.DESCRIPTION
The `Get-InstallSuccess` function polls the install success of a catalog item by retrieving its state
and status codes. It continues polling at specified intervals until the installation is either
completed or failed, or until the maximum number of attempts is reached.
.PARAMETER id
The ID of the catalog item to be checked. This parameter is mandatory.
.PARAMETER intervalInSeconds
The interval in seconds between each polling attempt. This parameter is optional and defaults to
60 seconds.
.RETURNVALUE
[bool] Returns `$true` if the installation is completed successfully, `$false` if the installation
is inactive or failed.
.EXAMPLE
$id = "b54f3dff-b297-ef11-8a69-7c1e520056af"
$intervalInSeconds = 60
$result = Get-InstallSuccess -id b54f3dff-b297-ef11-8a69-7c1e520056af
Write-Output "Installation success: $result"
#>
function Get-InstallSuccess {
param (
[Parameter(Mandatory)]
[string]$id,
[int]$intervalInSeconds = 60
)
$maxAttempts = 10
$attempts = 0
while ($attempts -lt $maxAttempts) {
$attempts++
# Retrieve the record
$response = Get-Record `
-setName 'mspcat_installhistories' `
-id $id `
-query '?$select=statecode,statuscode'
# Retrieve the record
# Wait until the state of the operation is inactive
if ($response.statecode -eq 1) {
if ($response.statuscode -eq 526430003) {
# When the statuscode value is 'Completed'
return $true
}
# Any other status code: 'Inactive' or 'Failed'
return $false
}
Start-Sleep -Seconds $intervalInSeconds
}
throw "Maximum number of polling attempts exceeded."
}
Usar la API web de Microsoft Dataverse
Use PowerShell y Visual Studio Code con la API web de Dataverse