Guest Paul Alexander Posted February 25, 2021 Posted February 25, 2021 HI We're trying to update a request using the API from a Powershell script, but nothing is happening (the code runs, and there are no errors, but the request doesn't get updated). The requestId is updated as a global value (we've used this script to update the timeline too, and that works fine) but I can't see why the custom field isn't being updated. Any thoughts please? thanks
Victor Posted February 25, 2021 Posted February 25, 2021 @Paul Alexander there should be an error returned there but perhaps you're not handling the API response there. Anyway, use double quotes (") instead of the apostrophe (') {"h_custom_a":"Test"}
Guest Paul Alexander Posted February 26, 2021 Posted February 26, 2021 Hi @Victor Just tried that, and we're getting the error (below). Sorry it's a bit messy, but basically we're trying to call the 'Requests::update' function with the customFields parameters: Error message is: Add-HB-Param : Cannot process argument transformation on parameter 'ParamAllowEmpty'. Cannot convert value "System.String" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0. At line:120 char:32 + Add-HB-Param "customFields" "{"h_custom_a":"test"}" + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Add-HB-Param], ParameterBindingArgumentTransformationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Add-HB-Param
Victor Posted February 26, 2021 Posted February 26, 2021 @Paul Alexander that does not look like a HB message, it looks like something the program/script developer can advise on...
Guest Paul Alexander Posted February 26, 2021 Posted February 26, 2021 @Victor the script developer has asked why HB seems to be asking for a 'system.boolean' value when we're trying to use the customFields parameter (Add-HB-Param "customFields" "{"h_custom_a":"test"}") when the template doesn't ask for ANY boolean values?
Steve Giller Posted February 26, 2021 Posted February 26, 2021 You've got double-quotes within double-quotes, which doesn't work. You'll need to use PowerShell's version of escaping the quotes, which I believe is to double-up like so: Add-HB-Param "customFields" "{""h_custom_a"":""test""}" but please check this in the PowerShell documentation because I'm no expert on that.
Guest Paul Alexander Posted March 1, 2021 Posted March 1, 2021 For anyone else in this predicament, the code we finally got to work was this (lots of quotes and + signs....I have no idea what all the syntax means but it works...):
BillP Posted May 11, 2021 Posted May 11, 2021 Here's a similar snippet of code, for those who find all the quotes and + signs confusing: $requestDetails = $requestOutput.Params.requestDetails | ConvertFrom-Json if ($requestDetails.h_custom_t -ne $TPEntity.Id) { [string]$CustomT = $TPEntity.Id $JsonCustomT = New-Object PSObject | Add-Member NoteProperty h_custom_t $CustomT -PassThru | ConvertTo-Json Add-HB-Param -ParamName "requestId" -ParamValue $requestDetails.h_pk_reference Add-HB-Param -ParamName "customFields" -ParamValue $JsonCustomT $requestOutput = Invoke-HB-XMLMC "apps/com.hornbill.servicemanager/Requests" "update" if ($requestOutput.Status -ne "ok") { # Write-Host "failed to set custom_t to $CustomT" } } What's going on here is that I'm using the h_custom_t field to store an external reference from Hornbill to the software development team's own SCRUM tracking system - the Hornbill Request Details are in $requestDetails and the SCRUM tracking story Id is in $TPEntity.Id If they don't match (which they won't, because up till now there's only been a one-way link), then I copy the Id into a new string $CustomT, and create a custom object from it, with a single, named field. ConvertTo-Json does the heavy lifting. Importantly, if the custom field itself contained quotes or other unusual characters, the ConvertTo-Json will take care of any necessary escape sequences or code conversions. Barely a quote in sight!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now