Powershell & NAV Web Services

eYe
Member Posts: 169
For me, it started off just to see if it was possible and to what extent I can use NAV Web Services in PowerShell. Here is an example to read, and update NAV.
I published Page 5050 - Contact Card as a web service.
Created an export for the list of Web Services, and export it to Settings.xml to use in my PowerShell script
This finds all the people for a specific Company and updates a new custom field "Registered"
I published Page 5050 - Contact Card as a web service.
Created an export for the list of Web Services, and export it to Settings.xml to use in my PowerShell script
OBJECT XMLport 50001 Web Services { OBJECT-PROPERTIES { Date=19/10/15; Time=07:50:33; Modified=Yes; Version List=EV; } PROPERTIES { Direction=Export; Format/Evaluate=C/SIDE Format/Evaluate; UseRequestPage=Yes; } ELEMENTS { { [{99CDBD45-35AC-4B12-917D-DE4351227FE4}]; ;Services ;Element ;Text } { [{BDC99D28-F3B9-4620-819A-65A7223A0CC3}];1 ;Service ;Element ;Table ; SourceTable=Table2000000076; SourceTableView=SORTING(Field3,Field9) WHERE(Field12=CONST(Yes)) } { [{B1AD82A5-34F9-4509-B425-B2EA8FBE81FC}];2 ;Name ;Attribute;Field ; DataType=Text; SourceField=Web Service::Service Name } { [{3A44F401-6EBE-406D-A6A5-32C686795EED}];2 ;Type ;Element ;Field ; DataType=Option; SourceField=Web Service::Object Type } { [{C21E3A9F-2545-4645-BD59-44B258B0B537}];2 ;Address ;Element ;Text ; Export::OnBeforePassVariable=BEGIN CASE "Web Service"."Object Type" OF "Web Service"."Object Type"::Page: Address := GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Page,"Web Service"."Object ID"); "Web Service"."Object Type"::Codeunit: Address := GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Codeunit,"Web Service"."Object ID"); ELSE Address := ''; END; END; } } EVENTS { } REQUESTPAGE { PROPERTIES { } CONTROLS { } } CODE { BEGIN END. } }
This finds all the people for a specific Company and updates a new custom field "Registered"
Param( [Parameter(Mandatory=$True)] [string]$CompanyNo ) #Read settings file and connect to web service [xml]$Settings = Get-Content 'C:\Script_Modules\Settings.xml' $servicenode = $Settings.Services.Service | Where-Object {$_.Name -eq 'Contact'} $service = New-WebServiceProxy -Uri $servicenode.Address -UseDefaultCredential true $filters = @() $ContactFilter = New-Object ('{0}.Contact_Filter' -f ($service.GetType().Namespace)) $ContactFilter.Criteria = ('{0}' -f $CompanyNo) $ContactFilter.Field = 'Company_No' $filters += $ContactFilter $ContactFilter = New-Object ('{0}.Contact_Filter' -f ($service.GetType().Namespace)) $ContactFilter.Criteria = 'Person' $ContactFilter.Field = 'Type' $filters += $ContactFilter # ##Alternatively, you can use this to return the entire contact list, and then filter the result set # #$Contacts = $service.ReadMultiple($null, '', 0) | Where-Object ` # {$_.Company_No -eq $CompanyNo -and $_.Type -eq 'Person'} $Contacts = $service.ReadMultiple($filters, '', 0); $Contacts | Format-Table foreach($contact in $contacts) { $contact.Registered = $true $service.Update([ref] $contact) } $Contacts = $service.ReadMultiple($filters, '', 0); $Contacts | Format-Table
Kind Regards,
Ewald Venter
Ewald Venter
1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions