cancel
Showing results for 
Search instead for 
Did you mean: 

Assign a Survey to Visit using c4codata API

thomaseadie
Discoverer
0 Kudos

Hello, I'm trying to use the c4codata API to create a Visit, attach a Survey, start the Visit, and update values. However I'm running into issues with attaching the Survey.

Here's what it looks like from the UI:

thomaseadie_0-1714409188637.png

With the API, those surveys are VisitWorklistItems as described here: https://help.sap.com/doc/d0f9ba822c08405da7d88174b304df84/CLOUD/en-US/index.html#/topic/VisitWorklis.... However those objects can't be created, so I'd like to know this can be done.

Thanks!

Edit:

For more info on what I've done so far, I'm creating a visit with a POST to 

 

activity/VisitCollection

 

 I can then see there are WorkItems already created for the Visit by making a GET to

 

activity/VisitWorklistItemCollection?$filter=ParentObjectID eq '<parent_id>'

 

Comparing the differences between a visit with a survey assigned and one without, the only difference is with the value of ExecutedIndicator. However if I try to update that using a PATCH to

 

activity/VisitWorklistItemCollection('<worklist_item_id>')

 

with the payload

 

{
    "ExecutedIndicator": true
}

 

It returns

 

{
    "error": {
        "code": "CX_ODATA_ANNOTATION_ERROR",
        "message": {
            "lang": "en",
            "value": "Update not allowed for properties: ExecutedIndicator. Check metadata for VisitWorklistItemCollection"
        }
    }
}

 

 Looking at the docs here: https://help.sap.com/doc/d0f9ba822c08405da7d88174b304df84/CLOUD/en-US/index.html#/topic/VisitWorklis..., it seems like it should be editable:

thomaseadie_0-1715123337241.png

However in the $metadata it doesn't, which seems to be the behaviour:

 

<EntityType Name="VisitWorklistItem">
    ...
    <Property Name="ExecutedIndicator" Type="Edm.Boolean" Nullable="true" sap:creatable="false" sap:updatable="false" sap:filterable="true"/>
</EntityType>

 

Accepted Solutions (0)

Answers (1)

Answers (1)

thomaseadie
Discoverer
0 Kudos

What ended up working was going Activity Planning > Routing Rules and setting up an Activity Plan that included the survey, and setting it to be assigned automatically.

This seems to be a batch process that runs periodically rather than something that happens as part of the visit being created, I found it can take a couple minutes for the survey to actually show up.

When creating the visit programatically I wait for the survey to be assigned by querying the following endpoint with a filter for the visit:

surveyresponse/SurveyResponseCollection?$filter=BusinessTransactionDocumentUUID eq '<visitObjectId>'

For some reason if the survey response doesn't exist and the filter doesn't match it just returns everything, whereas if it does it returns one.