WebService task returns all values in one field - How do I separate them? | XM Community
Skip to main content

I am working on creating a workflow to pull data into Qualtrics using a WebService Task. This task pulls the information over successfully, but all the information is in one field

Example of the input to the CodeTask:

{ "payload": { "actionId": "OCAC_g2EK1VxwCCGSZ8I", "chain": { "OCAC_zRzvocU2ECXfhLX": { "$.issues": "[{\"id\":92516,\"project\":{\"id\":183,\"name\":\"Service Requests\"},\"tracker\":{\"id\":17,\"name\":\"IT - Service Request\"},\"status\":{\"id\":18,\"name\":\"Closed\",\"is_closed\":true},\"css_classes\":\"issue tracker-17 status-18 priority-12 priority-default closed multieditable-container\",\"priority\":{\"id\":12,\"name\":\"Normal\"},\"author\":{\"id\":255,\"name\":\"Name Name\"},\"assigned_to\":{\"id\":119,\"name\":\"Name Name\"},\"subject\":\"FW: Vehicle 5487\",\"description\":\"<p> <br> <br>From: PD Repairs <br>Sent: Wednesday, October 16, 2024 11:03 AM<br>To: Names of those on email  <br>Subject: FW: Vehicle 5487<br> <br> <br>From: Name Name <br>Sent: Wednesday, October 16, 2024 11:03:21 AM (UTC-06:00) Central Time (US & Canada)<br>To: PD Repairs <br>Subject: Vehicle 5487<br>This morning I attempted to start vehicle 5487 and the computer would not turn on. I attempted multiple times with the vehicle running and received no response from the power button.<br> <br>Hopefully it was just the cold weather. The keys are on the board.<br> <br>Thank you,<br>Officer Name<br> <br>Get Outlook for iOS</p>\",\"start_date\":\"2024-10-16\",\"due_date\":null,\"done_ratio\":100,\"is_private\":false,\"is_favorited\":false,\"estimated_hours\":null,\"easy_email_to\":\"someone@here.org\",\"easy_email_cc\":\"department@here.org\",\"custom_fields\":m{\"id\":471,\"name\":\"Name Name\",\"internal_name\":null,\"field_format\":\"easy_lookup\",\"value\":2286,\"url\":\"https://someurl.gov/users/2286/profile.json\"},{\"id\":407,\"name\":\"IT Category\",\"internal_name\":null,\"field_format\":\"list\",\"value\":\"Hardware\"},{\"id\":408,\"name\":\"IT Subcategory\",\"internal_name\":null,\"field_format\":\"dependent_list\",\"value\":\"Workstation\"},{\"id\":396,\"name\":\"Associated Workstation(s)\",\"internal_name\":null,\"multiple\":true,\"field_format\":\"easy_lookup\",\"value\":,]},{\"id\":395,\"name\":\"Associated Server(s)\",\"internal_name\":null,\"multiple\":true,\"field_format\":\"easy_lookup\",\"value\":,]},{\"id\":397,\"name\":\"Associated Network Equipment\",\"internal_name\":null,\"multiple\":true,\"field_format\":\"easy_lookup\",\"value\":,]},{\"id\":398,\"name\":\"Associated Storage System(s)\",\"internal_name\":null,\"multiple\":true,\"field_format\":\"easy_lookup\",\"value\":,]},{\"id\":405,\"name\":\"Associated Solution\",\"internal_name\":null,\"multiple\":true,\"field_format\":\"easy_lookup\",\"value\":,]}],\"created_on\":\"2024-10-16T18:00:16Z\",\"updated_on\":\"2024-10-16T21:48:07Z\",\"closed_on\":\"2024-10-16T21:48:07Z\"},

{\"id\":92513,\"project\":{\"id\":183,\"name\":\"Service Requests\"},\"tracker\":{\"id\":17,\"name\":\"IT - Service Request\"},\"status\":{\"id\":18,\"name\":\"Closed\",\"is_closed\":true},\"css_classes\":\"issue tracker-17 status-18 priority-12 priority-default closed multieditable-container\",\"priority\":{\"id\":12,\"name\":\"Normal\"},\"author\":{\"id\":807,\"name\":\"Name Name\"},\"assigned_to\":{\"id\":110,\"name\":\"Name name\"},\"subject\":\"Rename holds = \\\"CONDITIONS OF APPROVAL\\\"\",\"description\":\"<p>Hello Name,<br> <br>Can you go in and rename all of our holds:<br> <br>Example:  <br>“Conditions of Approval – CODES” to “Conditions of Occupancy – CODES”<br>“Conditions of Approval – FIRE” to “Conditions of Occupancy – FIRE”<br>Etc. for all 7 departments plus Public Art as well.<br> <br>Change the word Approval to Occupancy.  <br> <br>Thanks buddy.<br> <br>Name Name CBO <br>Chief Building Official <br>(913) 971-9811 | OlatheKS.org<br>Building Codes Division - City of Olathe, Kansas<br>Setting the Standard for Excellence in Public Service<br> </p>\",\"start_date\":\"2024-10-16\",\"due_date\":null,\"done_ratio\":100,\"is_private\":false,\"is_favorited\":false,\"estimated_hours\":null,\"easy_email_to\":\"someone@here.org\",\"easy_email_cc\":\"someone@here.org, department@here.org\",\"custom_fields\":e{\"id\":471,\"name\":\"Name Name\",\"internal_name\":null,\"field_format\":\"easy_lookup\",\"value\":807,\"url\":\"https://someurl.gov/users/807/profile.json\"},{\"id\":407,\"name\":\"IT Category\",\"internal_name\":null,\"field_format\":\"list\",\"value\":\"Solution\"},{\"id\":408,\"name\":\"IT Subcategory\",\"internal_name\":null,\"field_format\":\"dependent_list\",\"value\":\"Energov\"},{\"id\":396,\"name\":\"Associated Workstation(s)\",\"internal_name\":null,\"multiple\":true,\"field_format\":\"easy_lookup\",\"value\"::]},{\"id\":395,\"name\":\"Associated Server(s)\",\"internal_name\":null,\"multiple\":true,\"field_format\":\"easy_lookup\",\"value\"::]},{\"id\":397,\"name\":\"Associated Network Equipment\",\"internal_name\":null,\"multiple\":true,\"field_format\":\"easy_lookup\",\"value\"::]},{\"id\":398,\"name\":\"Associated Storage System(s)\",\"internal_name\":null,\"multiple\":true,\"field_format\":\"easy_lookup\",\"value\"::]},{\"id\":405,\"name\":\"Associated Solution\",\"internal_name\":null,\"multiple\":true,\"field_format\":\"easy_lookup\",\"value\"::]}],\"created_on\":\"2024-10-16T17:00:24Z\",\"updated_on\":\"2024-10-16T20:59:01Z\",\"closed_on\":\"2024-10-16T20:59:01Z\"}];\n issues = JSON.parse(issues); // Assuming the issues are returned as a string, parse them into an object\n\n // Ensure we have issues to process\n if (!Array.isArray(issues) || issues.length === 0) {\n return { result: \"No issues to process\" };\n }\n\n // Retrieve the index from embedded data\n var indexStr = ~{e://Field/current_issue_index};\n var index = parseInt(indexStr || 0); // Convert to number and ensure it's valid\n\n // Check the bounds of the index to avoid out-of-range errors\n if (index >= issues.length) {\n return { result: \"No more issues to process\" };\n }\n\n // Extract the current issue from the list\n var currentIssue = issuestindex];\n\n // Handle missing properties with a fallback to empty strings or default values\n var projectName = currentIssue.project ? currentIssue.project.name : \"\";\n var trackerName = currentIssue.tracker ? currentIssue.tracker.name : \"\";\n var status = currentIssue.status ? currentIssue.status.name : \"\";\n var priority = currentIssue.priority ? currentIssue.priority.name : \"\";\n var author = currentIssue.author ? currentIssue.author.name : \"\";\n var assignedTo = currentIssue.assigned_to ? currentIssue.assigned_to.name : \"\";\n var subject = currentIssue.subject || \"\";\n var description = currentIssue.description || \"\";\n var startDate = currentIssue.start_date || \"\";\n var dueDate = currentIssue.due_date || null;\n var doneRatio = currentIssue.done_ratio || 0;\n var isPrivate = currentIssue.is_private || false;\n var isFavorited = currentIssue.is_favorited || false;\n var estimatedHours = currentIssue.estimated_hours || null;\n var easyEmailTo = currentIssue.easy_email_to || \"\";\n var createdOn = currentIssue.created_on || \"\";\n var updatedOn = currentIssue.updated_on || \"\";\n var closedOn = currentIssue.closed_on || \"\";\n\n // Extract custom fields\n var internalName = \"\";\n var itCategory = \"\";\n var itSubcategory = \"\";\n var associatedWorkstation = \"\";\n var associatedServer = \"\";\n var associatedNetworkEquipment = \"\";\n var associatedStorageSystem = \"\";\n var associatedSolution = \"\";\n\n if (currentIssue.custom_fields) {\n for (var i = 0; i < currentIssue.custom_fields.length; i++) {\n var field = currentIssue.custom_fields;i];\n if (field.id === 471) {\n internalName = field.name;\n } else if (field.id === 407) {\n itCategory = field.value;\n } else if (field.id === 408) {\n itSubcategory = field.value;\n } else if (field.id === 396) {\n associatedWorkstation = field.value;\n } else if (field.id === 395) {\n associatedServer = field.value;\n } else if (field.id === 397) {\n associatedNetworkEquipment = field.value;\n } else if (field.id === 398) {\n associatedStorageSystem = field.value;\n } else if (field.id === 405) {\n associatedSolution = field.value;\n }\n }\n }\n\n // Return the extracted fields\n var result = {\n projectName: projectName,\n trackerName: trackerName,\n status: status,\n priority: priority,\n author: author,\n assignedTo: assignedTo,\n subject: subject,\n description: description,\n startDate: startDate,\n dueDate: dueDate,\n doneRatio: doneRatio,\n isPrivate: isPrivate,\n isFavorited: isFavorited,\n estimatedHours: estimatedHours,\n easyEmailTo: easyEmailTo,\n internalName: internalName,\n itCategory: itCategory,\n itSubcategory: itSubcategory,\n associatedWorkstation: associatedWorkstation,\n associatedServer: associatedServer,\n associatedNetworkEquipment: associatedNetworkEquipment,\n associatedStorageSystem: associatedStorageSystem,\n associatedSolution: associatedSolution,\n createdOn: createdOn,\n updatedOn: updatedOn,\n closedOn: closedOn\n };\n\n // Increment the index for the next loop\n Qualtrics.SurveyEngine.setEmbeddedData('current_issue_index', index + 1);\n\n // Return the result to the Qualtrics Web Service Task\n return result;\n}\n", "contextId": "SV_5nGzDiAvJg5xTLw", "createdAt": 1729192655853, "customSaveHandler": true, "dependencies": { "OCAC_zRzvocU2ECXfhLX": "$.issues" ] }, "dynamic": false, "elementConfigured": true, "exports": c { "display_name": "result", "key": "result" }, { "display_name": "projectName", "key": "projectName" }, { "display_name": "trackerName", "key": "trackerName" }, { "display_name": "status", "key": "status" }, { "display_name": "priority", "key": "priority" }, { "display_name": "author", "key": "author" }, { "display_name": "assignedTo", "key": "assignedTo" }, { "display_name": "subject", "key": "subject" }, { "display_name": "description", "key": "description" }, { "display_name": "startDate", "key": "startDate" }, { "display_name": "dueDate", "key": "dueDate" }, { "display_name": "doneRatio", "key": "doneRatio" }, { "display_name": "isPrivate", "key": "isPrivate" }, { "display_name": "isFavorited", "key": "isFavorited" }, { "display_name": "estimatedHours", "key": "estimatedHours" }, { "display_name": "easyEmailTo", "key": "easyEmailTo" }, { "display_name": "internalName", "key": "internalName" }, { "display_name": "itCategory", "key": "itCategory" }, { "display_name": "itSubcategory", "key": "itSubcategory" }, { "display_name": "associatedWorkstation", "key": "associatedWorkstation" }, { "display_name": "associatedServer", "key": "associatedServer" }, { "display_name": "associatedNetworkEquipment", "key": "associatedNetworkEquipment" }, { "display_name": "associatedStorageSystem", "key": "associatedStorageSystem" }, { "display_name": "associatedSolution", "key": "associatedSolution" }, { "display_name": "createdOn", "key": "createdOn" }, { "display_name": "updatedOn", "key": "updatedOn" }, { "display_name": "closedOn", "key": "closedOn" } ], "icon": "https://www.xm-apps-static.com/assets/v1/APP_20aaddb5-1229-49f4-a0c2-25d1f72755ec/0.19.5/2ZlemZontaWGTTzN/images/logo.svg", "id": "PLUG_82724be1-02e7-44f9-a774-3f49a08b4a7a", "keyvalues": 2], "metadata": { "lazyLoadPipedText": true, "tags": " "wf-schematized", "survey" ], "worker": { "type": "runner" } }, "name": "Code", "outcomeId": "OC_W7mSij3gGEjUMfi", "ownerObject": { "brandId": "olathecx", "orgId": "olathecx", "userId": "UR_4MB9nKybyV0iwYZ" }, "replacementAppId": "", "summary": "Pull as an array", "surveyId": "SV_5nGzDiAvJg5xTLw", "taskNumber": 7, "taskRegistryId": "APP_20aaddb5-1229-49f4-a0c2-25d1f72755ec", "triggerAction": "CodeTask", "updatedAt": 1729194572352, "workspaceId": "SV_5nGzDiAvJg5xTLw", "workspaceType": "survey" }, "user": { "userId": "UR_4MB9nKybyV0iwYZ", "brandId": "olathecx" }, "executionData": { "workflowId": "MTW_3EhCGuTLAAOjTnJ-OC_W7mSij3gGEjUMfi", "runId": "", "actionId": "OCAC_g2EK1VxwCCGSZ8I", "contextId": "SV_5nGzDiAvJg5xTLw", "uniqueId": "MTW_3EhCGuTLAAOjTnJ", "outcomeId": "OC_W7mSij3gGEjUMfi", "taskToken": null, "attempt": 0, "orchestrator": "TEMPORAL" }, "policies": {} }

This is the input into the Code Task when the workflow is run. I cannot figure out the correct javascript for the Code task to separate all the fields like below so they can be mapped into the feedback survey:

THIS IS NOT FROM THE ABOVE DATA BUT A DIFFERENT DATE SO THE VALUES WILL NOT MATCH.

"projectName": "Service Requests",
"trackerName": "IT Service Requests",
"status": "Closed",
"priority": "Normal",
"author":"Name Name",
"assigned_to": "Name Name",
"subject": "Unblock Name Name Microsoft Office 365 Account",
"description": "<p>Plese Unblock Name Name Microsoft Office 365 Account</p>",
"start_date": ""2024-09-06",
"due_date": null,
"done_ratio": 100,
"is_private": false,
"is_favorited": false,
"estimated_hours": null,
"easy_email_to": "someone@here.ORG",
"internal_name": "Someone",
"IT Category": "Solution",
"IT Subcategory": "Office 365",
"Associated Workstation(s)": "",
"Associated Server(s)": "",
"Associated Network Equipment": "",
"Associated Storage System(s)": "",
"Associated Solution": "",
"created_on":"2024-09-06T13:52:29Z",
"updated_on":"2024-09-23T14:24:22Z",
"closed_on":"2024-09-23T14:24:22Z"
 

@SandraH It’s a JSON object with multiple layer and the webservice task already offer an path to save the return message as pipe-text to use later. Just use the test function in the Webservice task and go down layer by layer, each seperated by a “.”
For example, to pipe in userID in your: Code will be $.user.userId

Add custom path to get a specific field


You should use some JSON formater i.e: jsoneditoronline.org to get a better structured look at the object

Also, the JSON you put up here missing a “}”. This task is coding/tech heavy, so ask your IT guys if you have one.


Leave a Reply