I have a survey wich contains two steps. In the first step a new respondent is answering all questions. In the Survey Flow an Embedded Data Field is added called 'sts'. This field remains empty after the first step. After finishing an emailtrigger sends a message to another person. This emailmessage contains a retake link from the response and is set to not delete the original respons. This retakelink looks like:
https://mycompany.qualtrics.com/jfe/form/SV_1aBCd2EF3ghIJ4K?Q_R=R_X1Y2Z3k4l5m67NO&Q_R_DEL=0
Now the survey starts based on this retakelink. In the original response I want the Embedded Data Field 'sts' be filled with some info, like 'xyz'. But I can't get it to work. Below some screenshots:
In the Actions Tab I have set the event to 'All types'. No conditions is set. The task is set up to:
- Authentication = Token. I used the Token I found in the QualtricsID's screen.
- URL = https://mycompany.qualtrics.com/api/v3/responses/${e://Field/ResponseID}
- Request = PUT
- Content = JSON
- Datafields = 'sts' and 'xyz'
!
After I ran the retakelink, no data is changed in the original response. The field 'sts' remains empty.
I also tried Web Services in the Survey Flow section. Below the screenshot of the settings I used:
But when I click on the Test button I receive an errormessage: 404 - Not Found, The requested resource does not exist.
Can somebody help me setting up either option to amend the Embedded Data Field in the original response?
Kind regards and thanks in advance.
Nico Leussink
You're on the right track with the Web Service but the configuration is missing a couple of pieces.
The Update Response API documentation shows that two parameters are required (In addition to including the response ID in the URL, as you have done already):
1) surveyId
2) embeddedData
To add these to your Web Service block, you'll want to set it the 'Body Parameters' section as seen below. According to the documentation, the 'embeddedData' parameter is structured as a JSON object, so that's why it has the curly braces around the content (e.g., {"sts": "Test"}.
!
I also recommend capturing the HTTP response variables as you can see in the 'Embedded Data' section of the Web Service block. These will capture the HTTP response from when the Web Service fires and store it on the survey response that triggered the Web Service. This can be useful for troubleshooting purposes. Below, you can see what this looks like in the response data.
!
I hope that helps!
Hi KeirJ,
Just came across your post and wondered if this might help me with what I'm trying to do. I don't want to retake the survey in question but want to make an amendment to a question based on the followup data of a ticket. I can setup an action which if any of the followup data changes can result in a task which can update the ticket data. This works fine. But what I also need is to be able to align the response data in the original survey. This is a specific field which is about the type of feedback the response is about (eg. Complaint / General or Compliment). If this is possible, would you be kind enough to walk me through the steps to make this happen? From your post above I don't quite understand whether I need only to use the Web service request Task (the first picture) or whether I need to do something in the survey flow (a web service block in the survey flow). I understand the need to add some system based embedded fields for trouble shooting purposes.
I don't really know much about APIs, JSON, POST and GET etc. but hopefully what I am trying to do is feasible and so can pick it up as I go.
Thanks in advance
Rod Pestell
Hi Nico_Leussink ,
KierJ hasn't responded so I was wondering if you could kindly help me setup a similar action for my survey. Could you help with some guidance and the questions I had as per my post above?
Many thanks in advance
Rod Pestell
Update_Embedded_Data_Field_using_Web_Service.qsfHi Rod_Pestell,
Of course I can try to help you. As fas as I know you can only add/amend Embedded Data Fields.
I have created a short survey where you can test if this is what you want. A few things you need to change:
- Create a new survey from file and use the attached survey-file.
- Navigate to your account setings, click on Qualtrics IDs and find your API token. Copy this API token. Check the Qualtrics support page for more details: www.qualtrics.com/support/integrations/api-integration/overview
- Open the new created survey, navigate to Survey Flow, scroll down to the Web Service element, delete the fake X-API-TOKEN and paste your own X-API-TOKEN.
- In the URL address bar you can copy your SurveyID now and paste this into the field containing a fake surveyID now.
- Save this Survey Flow
Now test this survey. You have to give in your own Email address because I have added an Emailtrigger. The content of the email contains a socalled 'Retake link' where I have changed the last part of this link from 1 to 0. This means at Retake you will keep the original response. Make a selection and send the response.
You will now receive an email with this retake-link. Click on this link in your email. Notice that your previous choise is still the selected choise now. Now press on the button to go to the next page. Now select one of the options to change the content of the embedded data field sts. Now press on the Next button. You will receive an email again containing a retake link. But also please check the Data & Analysis tab as well and notice that the embedded data field 'sts' is changed.
Hope this helps you futher. If not, please contact me.
Hi Nico_Leussink ,
Thanks very much for the reply and the guidance. That's been really helpful. Together with Qualtrics support I've been able to get to where I want which is to use the Action/Task version of the Web Service. So when I make a change to a field in the follow-up section of a ticket, it will now update the entry in the survey.
I will come back shortly on this thread and share my process and settings in more detail as I'd think many other people are trying to figure out how to do this.
As you mention the only drawback is that it will only change embedded fields and not actual QID based answers. However, I'm thinking it might be possible as I know API can be used to edit these responses (so long as they haven't been edited manually!) as we got a 3rd party company to tidy up some data for us a little while back (convert dates from UK to US format). So it must be possible - the caveat I recall though is that the method used meant you had to record all responses (GET) and post them all back up again including the edited ones at the same time. If you didn't do it this way, you'd lose any data points you didn't include. Perhaps this is a little too programmatic heavy for this simple task to handle but worth investigating.
I'll be back shortly :)
Thanks again!
Rod Pestell
hi Nico_Leussink / All,
Just wanted to add an update on this as I've got stuck. as above I had managed to get a webservice task from within a ticket action working effectively. However, the solution I'm currently using will only do one field of embeddeddata field change at a time. I'm sure it can do more than one and it's just the JSON syntax I'm struggling with. Please see the pic attached. I've included two EmbeddedData fields
as soon as I save it though the 1st of the 2 embeddedData fields is lost
Can you or anyone advise when using this webservice task (from within the event based actions part of the system how you can do more than one embeddedData field at a time?
Thanks
Rod Pestell
HI All,
I think I solved it it was a simple comma!! {"field1":"value1", "field2":"value2"}. Doesn't anyone know using this JSON route as to whether there is a limit on the length of the JSON string?
Also, this is a No auth[icator] method but I still have to provide my API token, Survey and Response ID.... so would you regard this as still secure? Is this PUT command only allowable as I'm logged in with credentials?
Thanks
Rod Pestell
hi Nico_Leussink / All,
Just wanted to ask for your advise about the Webservice tasks and JSON.
I'm using the webservice task in a workflow to update an embedded field in a survey response when a ticket is updated (ie so not in a survey / survey flow but the workflow / action part of the system).
This works fine except when (in the original text box of the follow-up details) it includes a character return (\\n) or other non alphanumeric characters (eg double quotes). I have read up on this problem and apparantly you need to replace the character returns with something else or just remove them. I thought I could do this by using a code task before the webservice task, bringing in via piped text the contents of the text box and manipulating it but I'm struggling at that point as the \\n causes an error as the string is being taken literally before I can actually manipulate it, it seems.
Below is some test code just to try and prepare some variables that I then post in an email to check the end result.
function codeTask() {
var TxtClosingNotes = "${tck://form/TEXT/Closing%20notes/ResponseText}";
//var TxtClosingNotesStringify = JSON.stringify(TxtClosingNotes); //ignore this line - stringify I don't think is what I need to use
var TxtClosingNotesEdit = TxtClosingNotes.replace(new RegExp('\\\\\\\\n', 'g'), '
');
var TicketIDnumber = "${tck://Field/key}";
return {
result1: TxtClosingNotes,
result2: TxtClosingNotesEdit,
result3: TicketIDnumber
};
}
This code works fine when the source text has no \\n's. But when there are it give an error.
Looking in the workflow log, this is part of the input log for when it goes wrong:
"codeInput": "function codeTask() {\\n var TxtClosingNotes = \\"All afternoon teas were refunded also. \\n\\nRegards. \\n\\nTom Wright \\n \\n\\t\\nHead of Hospitality";\\n //var TxtClosingNotesStringify = JSON.stringify(TxtClosingNotes); \\n \\n var TxtClosingNotesEdit = TxtClosingNotes\\n \\n TxtClosingNotesEdit.replace(new RegExp('\\\\\\\\\\\\\\\\n', 'g'), '
');\\n \\n var TicketIDnumber = \\"T-4469\\";\\n\\n return {\\n result1: TxtClosingNotes,\\n \\tresult2: TxtClosingNotesEdit,\\n\\tresult3: TicketIDnumber\\n\\t};\\n\\n}",
With output error:
{
"name": "ACTIONS.ERROR_CODES.USER_CONFIGURATION_ERROR",
"message": "SyntaxError: Invalid or unexpected token",
"needRetry": false
}
This is the Input log for when it works ok. Notice there are no \\n's in the text part
"codeInput": "function codeTask() {\\n var TxtClosingNotes = \\"food and interactions with team - new menu - thanks and feedback passed on for review - apologised if they felt offended not our intention.\\";\\n //var TxtClosingNotesStringify = JSON.stringify(TxtClosingNotes); \\n \\n var TxtClosingNotesEdit = TxtClosingNotes\\n \\n TxtClosingNotesEdit.replace(new RegExp('\\\\\\\\\\\\\\\\n', 'g'), '
');\\n \\n var TicketIDnumber = \\"T-4611\\";\\n\\n return {\\n result1: TxtClosingNotes,\\n \\tresult2: TxtClosingNotesEdit,\\n\\tresult3: TicketIDnumber\\n\\t};\\n\\n}",
Can you advise how I get round this?
Thanks
Rod Pestell
Hi All,
Any thoughts on this at all. Would much appreciate some guideance.
Thanks
Rod Pestell
Hi Rod,
What possibly may work is to create a new Embedded Data Field. Then fill this Embedded Data Field with the information of its original Text Field. Normaly the CR's are then removed autmatically and should you be able to update the original field.
Can you give this a try?
Kind regards,
Nico Leussink
https://community.qualtrics.com/XMcommunity/discussion/comment/42074#Comment_42074Hi Nico_Leussink ,
Thanks for the reply. Worth a try, however I'm not sure how I can transfer the text from a text box in the followup section of a ticket to a traiditional embedded field you see in the survey D&A section without using a webservice task which is where is falls over as it's JSON?
Thanks
Rod Pestell
Do we have a fix for the carriage return for open text fields as this is breaking our simple workflows which were working fine in H1 2022 and now our webservices are failing because of the carriage return not parsing in the JSON - Body section even though they are plain-text type.
Even after applying the CodeTask still encountering issues on Carriage Return. Can seems to figure out the obvious, both codes the failure and successful ones look at the same, only when I went into the survey, I could see a carriage return in the text entry box, however post applying a backspace and re-submission, it was working fine.
The point of writing the CodeTask was to replace /n with '' for carriage returns, however unsure why it still does not pick up the carriage return and convert to /n.
Welcome any thoughts.
codeInput": "function codeTask() {\\n \\n var stringThatMightHaveNewLines = `Rating updated on 7th November.`;\\n\\tvar stringWithNoNewLines = stringThatMightHaveNewLines.replace(/\\\\n|\\\\\\"/g, '');\\n\\n\\treturn {\\n\\t\\tstringWithNoNewLines: stringWithNoNewLines\\n\\t}\\n}"
Can you write the code in a code block and then I'll compare it against my solution.
function codeTask() {
var qid91 =
`${q://QID91/ChoiceTextEntryValue}`;
var qid91_result =
qid91.
replace(/\\n+/g,'');
return{
qid91_result: qid91_result,
}
}
This solved
for
one but soon i realised it did not solve the multiline
and
quotes problem
as
every time someone writes a quote it comes back
as
\\
" e.g. \\"aalok\\". So I am still hunting for the right code to eliminate multiline and quotes issue now.
hi aalokjain
This is the critical line in my code. It will replace \\n with \\\\n and \\" with \\\\" which then lets the webservice work correctly.
var TxtClosingNotesEdit = `${tck://form/TEXT/Closing%20notes/ResponseText}`.replace(/\\n/g, '\\\\n').replace(/\\"/g, '\\\\"');
Notes: The types of apostrophes and dollar signs are critical. The problem is in part webservice parsing engine as it can't handle the special characters properly and doesn't put in the extra black slash in order to escape the escaped character (ie \\n and \\"). Without the extra back slash it messes up the JSON in the webservice which as a consequence fails.
However...... from my experience you can't just type this code in without the code task saying it's can't accept the code (it's the $ symbol this time). You'd normally need to escape the $ sign, ie \\$ in order to get the code task to run properly and for you to get the ~ch piped text code. The \\ creates a problem (something which I'm still waiting for the engineers to resolve) making it fail. The workaround is to use a backslash, get the piped text code, put it into the webservice task then go back into the code task and remove the \\ and ignore all the red dots and alerts saying the code won't work. It will work! But don't edit it to such an extent where another ~ch piped text variable is created or you have to repeat the whole process again!
Hope this helps someone - please upvote as then it's more likely to have a higher relevance in the search window of the community forum and more likely to help people then.
If you are contacting support on this, please reference this article. I assume many people have had or are having the same issue and Qualtrics need to be made aware of it's impact. To confirm, this is an issue which has been going on for more than a year and I'm surprised that it still hasn't been fixed or they haven't come back to me confirming if or when it's going to be fixed.
Thanks
Rod Pestell
Please accept this as the answer if this has got your code working now! :)
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.