Jump to content

logServiceRequest - struggling with questionFieldMap and connectionMap


Recommended Posts

Good morning,

I am looking to log tickets using the logServiceRequest API via Microsoft Flow but I am struggling with the two fields - questionFieldMap and connectionMap.

I have looked on the forums at other topics talking about questionFieldMap and tried the suggestions in there, but none of them work now.

1. When logging a Service Request, it uses pc2LogProCapture instead of logServiceRequest - and there are too many extra fields that I think it would be difficult to get the details from (icons, profile pictures) so it's difficult to replicate this and get it to work

2. Details on how to populate the questionFieldMap from other forum posts, provides the mapping but in testing it doesn't work with an error, something about child element mapping not being right or something.

3. There are no details anywhere on how to define the connectionMap

Please can someone advise.

Here is the latest request body - this works if I remove questionFieldMap and connectionMap then run the request in Postman

{
    "@service": "apps/com.hornbill.servicemanager/ServiceRequests",
    "@method": "logServiceRequest",
    "params": {
        "summary": "Set up Application access for testing",
        "description": "",
        "requestType": "Service Request",
        "customerId": "samwoo",
        "customerType": "0",
        "teamId": "HornbillTesting",
        "status": "status.new",
        "priorityId": "7",
        "categoryId": "424",
        "categoryName": "Application",
        "sourceType": "Request",
        "sourceId": "SR00139481",
        "serviceId": "153",
        "catalogId": "526",
        "catalogName": "Application Access [Linked Request]",
        "bpmName": "wbc-imt-application-access-request",
        "questionFieldMap": [
            {
                "form_id": "custom_details",
                "question": "Asset ID",
                "question_id": "h_custom_a",
                "answer": "2229",
                "field_type": "text",
                "entity_type": "request",
                "hbfield": {
                    "question": "Asset ID",
                    "field": {
                        "id": "h_custom_a",
                        "defLabel": "Asset ID",
                        "transLabel": "x",
                        "binding": "global.test.h_custom_a",
                        "noInvisibleValue": false,
                        "design": {
                            "isVisible": true,
                            "isMandatory": false,
                            "isReadOnly": false,
                            "showIfEmpty": false,
                            "extraClass": " "
                        },
                        "control": {
                            "type": "text"
                        },
                        "uid": "field-1-1"
                    },
                    "value": "2229"
                }
            },
            {
                "form_id": "custom_details",
                "question": "Asset Name",
                "question_id": "h_custom_b",
                "answer": "Testing App",
                "field_type": "text",
                "entity_type": "request",
                "hbfield": {
                    "question": "Asset Name",
                    "field": {
                        "id": "h_custom_b",
                        "defLabel": "Asset Name",
                        "transLabel": "x",
                        "binding": "global.test.h_custom_b",
                        "noInvisibleValue": false,
                        "design": {
                            "isVisible": true,
                            "isMandatory": false,
                            "isReadOnly": false,
                            "showIfEmpty": false,
                            "extraClass": " "
                        },
                        "control": {
                            "type": "text"
                        },
                        "uid": "field-2-1"
                    },
                    "value": "Testing Name"
                }
            }
        ],
        "connectionMap": {
            "connection.newManager": [
                {
                    "userId": "samwoo",
                    "userType": "account",
                    "display": "Samuel Wood (<hidden>)",
                    "comment": ""
                }
            ]
        }
    }
}

 

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Good evening,

Is this the correct input for questionFieldMap for the logServiceRequest API?

{
  "h_custom_e":"<REDACTED>",
  "h_custom_h":"<REDACTED>",
  "h_custom_i":"<REDACTED>",
  "h_custom_o":"<REDACTED>",
  "h_custom_21":"2023-01-09 00:00:00"
}

In my PowerShell script, I have everything else working (including the questions field) and the ticket is logged successfully, except the input for questionFieldMap partially works... it only maps to h_custom_21 and not the other fields defined above. The above is the output when running the variable in the terminal on VSCode, I just redacted the sensitive information.

I did try to do it differently and it doesn't work at all if it comes over like this (with each field as a separate child) - so I am assuming the above format is correct, I just can't work out why it's only mapping to the last in the JSON Object despite the whole thing going through with no errors.

[
  {
    "h_custom_e":"<REDACTED>"
  },
  {
    "h_custom_h":"<REDACTED>"
  },
  {
    "h_custom_i":"<REDACTED>"
  },
  {
    "h_custom_o":"<REDACTED>"
  },
  {
    "h_custom_21":"2023-01-09 00:00:00"
  }
]

Any help would be appreciated.

@Steve G sorry for picking on you but I have seen you respond to other people's requests on the forums about the logServiceRequest API in the past, wondering if you might be able to quickly spot the issue?

Thanks,

Samuel

Link to comment
Share on other sites

I just did another test by removing the part that generates the "h_custom_21" key/value, and now nothing is populating. This gives me a sense that there is a defect somewhere as none of the VARCHAR(255) fields are being populated.

Link to comment
Share on other sites

Thanks @Steve Giller - Would be good to see if someone else could offer any insights as well.

In fact, I can also confirm this issue with the /Requests/update API as well.

https://api.hornbill.com/apps/com.hornbill.servicemanager/Requests?op=update

The bit that runs to update the ticket:

$customFields = [PSCustomObject]@{}
$customFields | Add-Member -MemberType NoteProperty -Name 'h_custom_h' -Value 'han<REDACTED>'
$customFields | Add-Member -MemberType NoteProperty -Name 'h_custom_e' -Value 'Hannah <REDACTED>'

$outcome = Update-HB-Request-CustomFields -requestid 'SR00168595' -customFields ($customFields | ConvertTo-Json -Compress)

This is what the JSON looks like:

{"h_custom_h":"han<REDACTED>","h_custom_e":"Hannah <REDACTED>"}


This is the function I built to work alongside the HornbillAPI:

function Update-HB-Request-CustomFields
{
	param (
		[Parameter (
			Mandatory = $true
		)]
		[string]$requestid,

		[Parameter (
			Mandatory = $true
		)]
		[string]$customFields

	)

	Add-HB-Param -ParamName 'requestId' -ParamValue $requestid -ParamAllowEmpty $false
	Add-HB-Param -ParamName 'customFields' -ParamValue $jsonObject -ParamAllowEmpty $false

	$xmlmcOutput = Invoke-HB-XMLMC 'apps/com.hornbill.servicemanager/Requests' 'update'

	return $xmlmcOutput
}

This is the response running the function:
image.png.cf308b6624ef85ca4d4e03510c2b4870.png


No updates to the request:

image.png.54b6da58106101b979a78239913dff17.png
(Ignore the T, I added that via the ticket to see if it was working)

 

Could the new Custom Fields recently added have knocked out some of the APIs?

Link to comment
Share on other sites

Evening @samwoo,

I've just tested updating those custom fields using the Requests:update API, and it seems to be working fine:

image.png

On the right is the call I made in Postman to the API, with the XML payload & JSON content for the custom fields, and the left is the fields as populated by this call, so I'm not sure why it's not working at your end. 

Looks like you're using the HornbillAPI module, so it'd be worth outputting the content of the Get-HB-Params cmdlet to see what is actually being sent (before the Invoke-HB-XMLMC call, as that clears the params), should help with debugging.

Let me know how you get on.

Cheers,

Steve 

Link to comment
Share on other sites

@CraigP - Genius! 

You know when you've been looking at something for so long, you cannot see the obvious... thank you, it works! 

@Steve G

Thanks for the tip, in an ideal world it would be better to use the questionFieldMap field using the logServiceRequest Service. When I get a moment, I'll use your tip to find out what is being produced before initiating it.

Link to comment
Share on other sites

Yes, been there!

Just to confirm, I've been working on raising requests with the API recently and have successfully included the questionFieldMap parameter.

I haven't tested yours exactly, but this JSON format seems to match what I've used, so I can only assume there must be something up with how you're populating e,h,i and o.

{
  "h_custom_e":"<REDACTED>",
  "h_custom_h":"<REDACTED>",
  "h_custom_i":"<REDACTED>",
  "h_custom_o":"<REDACTED>",
  "h_custom_21":"2023-01-09 00:00:00"
}
Link to comment
Share on other sites

Hi @Steve G,

I outputted using your tip (Get-HB-Params), and weirdly the JSON within the XML comes out as HTML Encoded causing the output to look like this:
image.thumb.png.fef71717b34e4e1000a4987e92273ce8.png

Now weirdly, the JSON within the <questions> element is working fine. But the JSON within the <questionFieldMap> element only updates the last custom field defined (h_custom_21).

I at least have a workaround thanks to @CraigP's help to update the request after it's been logged, though I haven't noticed anything yet, I do worry that the BPM starting at the point of logging the ticket and me updating the request after the ticket has been logged, may mean that certain bits of information could be missed in the BPM instance at the beginning.

I suspect that once I produce the Email Template to notify the Leaver's Manager that the ticket has been logged at the beginning, it will not be able to capture the values of these custom fields... so at the moment all I can think of to work around this is to make sure the ticket is paused or put on-hold for 1 minute (if possible) then follow that up with a "Get Request Details" node.

Now I'm not 100% sure the HTML encoding is an issue (it might be, I guess it depends on the endpoint and its ability to parse the encoded values?) but I wonder if you might consider creating and supporting a new version of the HornbillAPI PowerShell module (maybe called HornbillAPI_JSON?) that produces the params as a JSON instead of XML and have that sent over instead, which might prevent this issue from occurring?

Thanks,

Samuel

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...