Jump to content

ServiceRequests/logServiceRequest API


Recommended Posts

I'm trying to raise a Service Request with the API with the progressive capture fields/questions filled in.

Can I please have some clarification on what is required by the Questions and QuestionFieldMap parameters on the LogServiceRequest API operation?

I'm under the impression that these want some kind of JSON object, but what properties need to be filled in for each? What is the difference between these parameters?

I found this old thread - however the JSON shown in the screenshot seems quite complicated. Is there a relatively simple way to build the required JSON object?

Link to comment
Share on other sites

  • 8 months later...

I'm attempting to raise a request using the logServiceRequest API call in PowerShell.

I had managed to do this successfully when I was investigating this last year, but I am now getting the failedToLog error - "XmlWriter::add: Unsupported value for \"h_entity_type\"".

This implies to me that either "request" is not the correct entity type (even though this is what is returned when I run Questions:queryExec on an existing request of the type I'm trying to raise), or I may need to provide the "questions" parameter with something other than JSON (perhaps XML?). Is this correct? Or if JSON is suitable for this, can someone please have a look at the below example JSON and tell me where I may be going wrong?

[{
        "h_entity_type":  "request",
        "h_question_id":  "h_custom_b",
        "h_question":  "Origin of Request",
        "h_field_type":  "radioset",
        "h_form_id":  "requestOrigin",
        "h_language":  "en-GB",
        "answer":  "Automated Alert"
    },
    {
        "h_entity_type":  "request",
        "h_question_id":  "field_Name",
        "h_question":  "Name",
        "h_field_type":  "text",
        "h_form_id":  "CustomForm",
        "h_language":  "en-GB",
        "answer":  "TestName"
    },
    {
        "h_entity_type":  "request",
        "h_question_id":  "field_Description",
        "h_question":  "Description",
        "h_field_type":  "textarea",
        "h_form_id":  "CustomForm",
        "h_language":  "en-GB",
        "answer":  "TestDesc"
    }]

 

Secondly, can someone please provide example JSON for the questionFieldMap parameter? The API documentation does not give an example of what this needs to contain.

Link to comment
Share on other sites

Hi @Steve Giller

Sorry but I don't think that has anything to do with my query. That parameter is optional (one assumes it is redundant to tell the "logServiceRequest" API that you want to log a service request), and the error I'm getting is referring to the entity type, not request type. I have now added the requestType parameter anyway, but as expected it has not changed the error.

It seems that I've either provided the wrong h_entity_type (but again, I copied the question information returned by the questions queryexec API on an existing request, which returns "request" as the h_entity_type for each question), or the format in which I've provided the questions is wrong.

I appreciate if this is not your area of expertise, but then please have you passed this on to a colleague who can answer my questions?

Link to comment
Share on other sites

Sorry, as you referred to the error immediately after saying you were calling the logServiceRequest API I assumed that's what you were talking about - and as there is no entityType within that call I mistakenly presumed it was requestType.

 

Link to comment
Share on other sites

On a side note, I've now noticed that every time I've run my script to test, despite returning an exception called "failedToLog" it has in fact still been logging blank requests on the system. This makes troubleshooting this quite frustrating.

Link to comment
Share on other sites

Thanks Gareth. I don't believe the Service has a default BPM, but I have already set the bpmName parameter.

For reference I have the following parameters set:

requestType
serviceId
questions
catalogId
catalogName
bpmName

I've copied these details as they appear for the catalog item in the h_itsm_service_catalog table

Link to comment
Share on other sites

Thanks. As I mentioned in the original post in this thread, I did manage to get it to work after that post last year. The "relatively simple way to build the required JSON object" I found at the time was to run Questions:queryExec on an existing request of the type I was trying to raise and change the answers as required. It did work at the time, but now upon revisiting it I'm getting this error.

Just to confirm, I've tried removing the questions parameter and it runs successfully (without populating the question form obviously), so it has to be the information/format of the information I'm providing there.

I've also tried running DEV tools while raising a request in app as per that old thread, but found it raised the request using pc2LogProcapture instead, which seemingly requires a significantly more complex JSON object for its "payload" parameter. If there is a way to get the app to trigger ServiceRequests:logServiceRequest (or Incidents:logIncident) instead, please let me know.

Link to comment
Share on other sites

I can only reiterate the original suggestion of engaging with Expert Services.

You will get answers here, but there are no timescales and the nature of a public forum may mean that certain things may not be easily discussed.

The Product is constantly evolving, if the SM Application has moved forward to use pc2LogProcapture there will not be a way to revert it to older functionality.

Link to comment
Share on other sites

@CraigP questions are for the values of questions and answers, questionsFieldMap is for any mappings that you have for answers (the answers mapped to request fields). If you are simply looking to have a set of questions and answers on a request then this thread can be useful:

For example below is a payload to raise an Incident with

Summary: Test Summary
Description: Test Description
No customer (if a customer is required then <customerId> and <customerType> would have to be set)
Service: 666 (this is the ID of the service of the request, needs to be a value for a service in your instance)
Questions:
Field 1 (type Text): 123 
Field 2 (type Textarea): 456

<methodCall service="apps/com.hornbill.servicemanager/Incidents" method="logIncident">
<params>
<summary>Test Summary</summary>
<description>Test Description</description>
<requestType>Incident</requestType>
<customerId/>
<customerType>0</customerType>
<serviceId>666</serviceId>
<questions>[{"form_id":"form_1","question":"Field 1","question_id":"field_1","answer":"123","answer_value":"123","field_type":"text","entity_type":"request","hbfield":{"question":"Field 1","field":{"id":"field_1","defLabel":"Field 1","transLabel":"x","binding":"global.form_1.field_1","noInvisibleValue":false,"design":{"isVisible":true,"isMandatory":false,"isReadOnly":false,"showIfEmpty":false,"extraClass":" "},"control":{"type":"text"},"uid":""},"value":"123"}},{"form_id":"form_1","question":"Field 2","question_id":"field_2","answer":"456","answer_value":"456","field_type":"textarea","entity_type":"request","hbfield":{"question":"Field 2","field":{"id":"field_2","defLabel":"Field 2","transLabel":"x","binding":"global.form_1.field_2","noInvisibleValue":false,"design":{"isVisible":true,"isMandatory":false,"isReadOnly":false,"showIfEmpty":false,"extraClass":" "},"control":{"type":"textarea"},"uid":""},"value":"456"}}]</questions>
</params>
</methodCall>

image.png

It is a simple question capture but it should give you some guidance on how the JSON string would need to look for adding questions on requests. Please be mindful that the payload can differ if we have things like translations or some very specific capture configuration that you want to mimic in the payload (which are actually not relevant for the API, this is mostly for how the capture works when the user inputs data in UI). I will put the expert service request on hold until you have a chance to review this. If you still have any further queries and/or need assistance with this I will allocate the expert service request to one of our tech specialists and they will progress this forward.

 

Link to comment
Share on other sites

  • 4 weeks later...

Good morning,

I have written a PowerShell Function to make it easy to produce the questions JSON and it works at a basic level, but I was looking for some assistance to enhance it:
https://github.com/WoodSam90/fnc_New-HB-Form-Questions/blob/main/fnc_New-HB-Form-Questions.ps1

  1. What are the list of available Field Types?
    1. Do different field type cause differences to the JSON? For example, different properties for different field types?
      1. If so, what are the differences between them all?
         
  2. What are the different Entity Types?
    1. Again do different Entity Types mean the JSON will be different?

 

Finally, indirectly related to the above, when a ticket is logged via API with these questions, how can they be accessed via the BPM, as these don't have a intelligent capture to link back to since the questions are populated outside of Hornbill.

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...