Skip to content

Commit

Permalink
Formating
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanNairz committed Nov 8, 2022
1 parent 04686f4 commit 021e2e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
32 changes: 16 additions & 16 deletions Files/powerEvents/Events/ErpService.Lifecycle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ function Test-ErpItemAndBOMForVaultFileOrVaultItem {
#Attention!!! When changing inside this function please check if you have to change somthing in "Check-Boms" function, beacause the functions are similare
Log -Begin
$number = GetEntityNumber -Entity $Entity
if(-not $number) {
if (-not $number) {
Add-VaultRestriction -EntityName $number -Message "There is no erp material linked to this entity!"
}

$erpMaterial = Get-ERPObject -EntitySet "Materials" -Keys @{ Number = $number }
if ($? -eq $false) {
return
}
}

if (-not $erpMaterial) {
Add-VaultRestriction -EntityName $number -Message "An item with the number '$($number)' does not exist in the ERP system."
Add-VaultRestriction -EntityName $number -Message "An item with the number '$($number)' does not exist in the ERP system."
return
}
}
if ($Entity._Extension -eq "ipt") {
return
}
Expand All @@ -44,15 +44,15 @@ function Test-ErpItemAndBOMForVaultFileOrVaultItem {
#>

$erpBomHeader = Get-ERPObject -EntitySet "BomHeaders" -Keys @{Number = $number } -Expand "BomRows"
if ($? -eq $false) {
return
}
if ($? -eq $false) {
return
}

if (-not $erpBomHeader) {
Log -Message "Bomheader doesn't exist yet and is new!"
Log -Message "Bomheader doesn't exist yet and is new!"
Add-VaultRestriction -EntityName $number -Message "Open the BOM Window, because the ERP BOM is different then in Vault: BOM does not exist in ERP!"
return
}
}

Log -Message "Bom head exists! Check if rows need to be added/updated"
$vaultBomRows = GetVaultBomRows -Entity $Entity
Expand Down Expand Up @@ -117,13 +117,13 @@ function RestrictItemRelease($items) {
Log -End
}

function StartSynchronizeJob($file)
{
function StartSynchronizeJob($file) {
# since Synchronize Properties gets triggered already by powerEvents, disable it in the Vault configuration!
Write-Host "Adding job 'Synchronize Properties' for file '$($file._Name)' to queue."
Add-VaultJob -Name "autodesk.vault.syncproperties" -Parameters @{
"FileVersionIds"=$file.Id;
"QueueCreateDwfJobOnCompletion"=$true} -Description "Synchronize properties of file: '$($file._Name)'"
"FileVersionIds" = $file.Id;
"QueueCreateDwfJobOnCompletion" = $true
} -Description "Synchronize properties of file: '$($file._Name)'"
}

Register-VaultEvent -EventName UpdateFileStates_Post -Action 'AddPdfJob'
Expand All @@ -136,23 +136,23 @@ function AddPdfJob($files, $successful) {
StartSynchronizeJob($file)
$jobType = "ErpService.Create.PDF"
Write-Host "Adding job '$jobType' for file '$($file._Name)' to queue."
Add-VaultJob -Name $jobType -Parameters @{ "EntityId" = $file.Id; "EntityClassId" = "FILE"} -Description "Create PDF for file '$($file._Name)' and upload to ERP system" -Priority 110
Add-VaultJob -Name $jobType -Parameters @{ "EntityId" = $file.Id; "EntityClassId" = "FILE" } -Description "Create PDF for file '$($file._Name)' and upload to ERP system" -Priority 110
}
Log -End
}

Register-VaultEvent -EventName UpdateItemStates_Post -Action 'AddItemPdfJob'
function AddItemPdfJob($items) {
Log -Begin
$releasedItems = @($items | Where-Object { $_._ReleasedRevision -eq $true})
$releasedItems = @($items | Where-Object { $_._ReleasedRevision -eq $true })
foreach ($item in $releasedItems) {
$attachedDrawings = Get-VaultItemAssociations -Number $item._Number
Write-Host "Found '$($attachedDrawings.Count)' files which are valid to add a PDF job for!"
foreach ($file in $attachedDrawings) {
StartSynchronizeJob($file)
$jobType = "ErpService.Create.PDF"
Write-Host "Adding job '$jobType' for file '$($file._Name)' to queue."
Add-VaultJob -Name $jobType -Parameters @{ "EntityId" = $file.Id; "EntityClassId" = "FILE"; "ItemNumber" = $item._Number} -Description "Create PDF for file '$($file._Name)' and upload to ERP system" -Priority 110
Add-VaultJob -Name $jobType -Parameters @{ "EntityId" = $file.Id; "EntityClassId" = "FILE"; "ItemNumber" = $item._Number } -Description "Create PDF for file '$($file._Name)' and upload to ERP system" -Priority 110
}
Log -End
}
Expand Down
3 changes: 1 addition & 2 deletions Files/powerJobs/Jobs/ErpService.Create.PDF.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ if ($openResult) {
$PDFfile = Add-VaultFile -From $localPDFfileLocation -To $vaultPDFfileLocation -FileClassification DesignVisualization -Hidden $hidePDF
$file = Update-VaultFile -File $file._FullPath -AddAttachments @($PDFfile._FullPath)

if($Job.ItemNumber)
{
if ($Job.ItemNumber) {
# Make sure you have permissions to modify released items before you use this Job for items with lifecycle change
Update-VaultItem -Number $Job.ItemNumber -AddAttachments @($PDFfile._FullPath)
}
Expand Down

0 comments on commit 021e2e8

Please sign in to comment.