{"id":832,"date":"2020-10-26T16:41:42","date_gmt":"2020-10-26T21:41:42","guid":{"rendered":"https:\/\/asberry.org\/blog_tech\/?p=832"},"modified":"2020-10-26T16:49:45","modified_gmt":"2020-10-26T21:49:45","slug":"tcc-powershell-csv-to-set-filters","status":"publish","type":"post","link":"https:\/\/asberry.org\/blog_tech\/?p=832","title":{"rendered":"TCC &#038; Powershell &#8211; CSV to Set Filters"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If you&#8217;ve been working with TCC for any length of time you&#8217;ll know the purple squirrel, rainbow unicorn and pot at the end of the rainbow is being able to set the filters based on a CSV. This ability would mark a boon for automating ad hoc integrations. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now there are options, Python could pull it off but Python doesn&#8217;t live and play on a stock server I run across 95% of the time. Powershell does however, well it usually lives there, not sure how much play is involved.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In any case, it turns out we can do this whole process in Powershell without a whole bunch of headache. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; light: false; title: ; toolbar: true; notranslate\" title=\"\">\n#Declare variables\n$sourcePath = &quot;..\\..\\scripts\\mappingFiles\\mappingContestNumberToJobCode.csv&quot;\n$targetPath = &quot;..\\..\\scripts\\mappingFiles\\mappingFilterList.txt&quot;\n$targetContent = @()\n$outputContent = New-Object System.Text.UTF8Encoding $false\n#Loop through source file to build filter\nImport-Csv $sourcePath | ForEach-Object {\n    $targetContent += &quot;&lt;quer:string&gt;$($_.Requisition)&lt;\/quer:string&gt;&quot;\n}\n#Write out file as UTF8 no BOM\n&#x5B;System.IO.File]::WriteAllLines($targetPath, $targetContent, $outputContent)\n#Update export specificaitons with the new filter set\n((Get-Content -path ..\\..\\scripts\\RequisitionExport\\RequisitionExportTemplate_sq.xml -Raw) -replace &#039;FilterList&#039;, (Get-Content -path  ..\\..\\scripts\\mappingFiles\\mappingFilterList.txt -Raw)) | Set-Content -Path ..\\..\\scripts\\RequisitionExport\\RequisitionExport_sq.xml;\n((Get-Content -path ..\\..\\scripts\\RequisitionMappingExport\\RequisitionMappingExportTemplate_sq.xml -Raw) -replace &#039;FilterList&#039;, (Get-Content -path  ..\\..\\scripts\\mappingFiles\\mappingFilterList.txt -Raw)) | Set-Content -Path ..\\..\\scripts\\RequisitionMappingExport\\RequisitionMappingExport_sq.xml;\n((Get-Content -path ..\\..\\scripts\\RequisitionCollaboratorExport\\RequisitionCollaboratorExportTemplate_sq.xml -Raw) -replace &#039;FilterList&#039;, (Get-Content -path  ..\\..\\scripts\\mappingFiles\\mappingFilterList.txt -Raw)) | Set-Content -Path ..\\..\\scripts\\RequisitionCollaboratorExport\\RequisitionCollaboratorExport_sq.xml;\n((Get-Content -path ..\\..\\scripts\\RequisitionOpenExport\\RequisitionOpenExportTemplate_sq.xml -Raw) -replace &#039;FilterList&#039;, (Get-Content -path  ..\\..\\scripts\\mappingFiles\\mappingFilterList.txt -Raw)) | Set-Content -Path ..\\..\\scripts\\RequisitionOpenExport\\RequisitionOpenExport_sq.xml;\n((Get-Content -path ..\\..\\scripts\\SourcingRequestExport\\SourcingRequestExportTemplate_sq.xml -Raw) -replace &#039;FilterList&#039;, (Get-Content -path  ..\\..\\scripts\\mappingFiles\\mappingFilterList.txt -Raw)) | Set-Content -Path ..\\..\\scripts\\SourcingRequestExport\\SourcingRequestExport_sq.xml;\n((Get-Content -path ..\\..\\scripts\\CandidateMatchExport\\CandidateMatchExportTemplate_sq.xml -Raw) -replace &#039;FilterList&#039;, (Get-Content -path  ..\\..\\scripts\\mappingFiles\\mappingFilterList.txt -Raw)) | Set-Content -Path ..\\..\\scripts\\CandidateMatchExport\\CandidateMatchExport_sq.xml;\n((Get-Content -path ..\\..\\scripts\\RequisitionQuestionExport\\RequisitionQuestionExportTemplate_sq.xml -Raw) -replace &#039;FilterList&#039;, (Get-Content -path  ..\\..\\scripts\\mappingFiles\\mappingFilterList.txt -Raw)) | Set-Content -Path ..\\..\\scripts\\RequisitionQuestionExport\\RequisitionQuestionExport_sq.xml;\n((Get-Content -path ..\\..\\scripts\\RequisitionOtherLocationExport\\RequisitionOtherLocationExportTemplate_sq.xml -Raw) -replace &#039;FilterList&#039;, (Get-Content -path  ..\\..\\scripts\\mappingFiles\\mappingFilterList.txt -Raw)) | Set-Content -Path ..\\..\\scripts\\RequisitionOtherLocationExport\\RequisitionOtherLocationExport_sq.xml;\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve been working with TCC for any length of time you&#8217;ll know the purple squirrel, rainbow unicorn and pot at the end of the rainbow is being able to set the filters based on a CSV. This ability would mark a boon for automating ad hoc integrations. Now there are options, Python could pull [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[23],"tags":[],"class_list":["post-832","post","type-post","status-publish","format-standard","hentry","category-powershell","author-aron"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4bBkH-dq","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=832"}],"version-history":[{"count":3,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/832\/revisions"}],"predecessor-version":[{"id":835,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/832\/revisions\/835"}],"wp:attachment":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}