I would like to be able to manage files (images) and create files (minified css/js) on my local filesystem (and check into sourcecontrol), and have a PowerShell script to create/update/delete these files on my PowerApps Portal in the WebFiles.
I have been playing with PowerShell, and I'm able to update an annotation (the actual file record connected to an adx_webfile, but I have no clue how to create a new adx_webfile entry and the corresponding annotation for the file contents.
Some things I did to update the contents of the annotation belonging to an existing adx_webfile:
param(
[string]$organization = "myOrg",
[string]$username = "serge.van.den.oever@macaw.nl",
[string]$password = "myPassword",
[string]$filename = "theme.css",
[string]$content = "Make my day"
)
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
Install-Module -Name Microsoft.Xrm.Data.PowerShell
Import-Module -Name Microsoft.Xrm.Data.PowerShell
$conn = Get-CrmConnection -DeploymentRegion EMEA -OnLineType Office365 -Credential $mycreds -OrganizationName $organization
$base64encodedContent = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($content))
$fetchAnnotation = @"
<fetch>
<entity name="annotation" >
<filter>
<condition attribute="filename" operator="eq" value="$filename" />
</filter>
</entity>
</fetch>
"@
$records = Get-CrmRecordsByFetch -conn $conn -Fetch $fetchAnnotation
if ($records.Count -ne 1) {
write-error "Expected file '$filename' not found"
exit 1
}
$fileRecord = $records.CrmRecords[0]
$fileRecord.documentbody = $base64encodedContent
Set-CrmRecord -conn $conn -CrmRecord $fileRecord
But this only works on existing annotations that already belong to an axd_webfile.
I already used export tooling to investigate what fields are involved:
<entities xmlns:xsd="">www.w3.org/.../XMLSchema" xmlns:xsi="">www.w3.org/.../XMLSchema-instance" timestamp="2020-01-09T20:26:23.7143227Z">
<entity name="adx_webfile" displayname="Web File">
<records>
<record id="7c972589-66ee-4c11-be72-193570c03355">
<field name="adx_contentdisposition" value="756150000" />
<field name="adx_enabletracking" value="False" />
<field name="adx_excludefromsearch" value="True" />
<field name="adx_hiddenfromsitemap" value="False" />
<field name="adx_name" value="theme.css" />
<field name="adx_parentpageid" value="87cdfb86-e3c8-48d7-8a99-c6fb2cbcb845" lookupentity="adx_webpage" lookupentityname="Home" />
<field name="adx_partialurl" value="theme.css" />
<field name="adx_publishingstateid" value="38c7d71a-31fd-4c2a-b7b0-fa2cc7381654 lookupentity="adx_publishingstate" lookupentityname="Published" />
<field name="statecode" value="0" />
<field name="statuscode" value="1" />
<field name="adx_webfileid" value="7c972589-66ee-4c11-be72-193570c03355" />
<field name="adx_websiteid" value="f46b70cc-580b-4f1a-87c3-41deb48eb90d" lookupentity="adx_website" lookupentityname="Starter Portal" />
</record>
</records>
<entity name="annotation" displayname="Note">
<records>
<record id="eef1b8e5-a7f7-4efd-b0a1-f617db2dd52a">
<field name="documentbody" value="Base64" />
<field name="filename" value="theme.css" />
<field name="filesize" value="50798" />
<field name="isdocument" value="True" />
<field name="mimetype" value="text/css" />
<field name="annotationid" value="eef1b8e5-a7f7-4efd-b0a1-f617db2dd52a" />
<field name="objecttypecode" value="adx_webfile" />
<field name="objectid" value="7c972589-66ee-4c11-be72-193570c03355" lookupentity="adx_webfile" />
</record>
</records>
<m2mrelationships />
</entity>
<entities>
But don't know how to go from here. Any suggestions would be appreciated!