When importing fields from a Contacts List, corresponding embedded data fields include dots (.). For example, here's the name of one embedded data that gets automatically created on Contact List import:
result.elements.0.embeddedData.V1
In my survey, I want to access the value stored in this embedded data field. But the getEmbeddedData() javascript method that Qualtrics provides apparently doesn't like dots.
For a simpler example, I shortened the above embedded data name to V.1:
Qualtrics.SurveyEngine.getEmbeddedData('V.1'); // returns null
and a null value is returned.
If I change the embedded data field name to V1 (no .), then the method returns the correct value:
Qualtrics.SurveyEngine.getEmbeddedData('V1'); # returns correct value
In the case where there's a dot in the name, I tried escaping with \\ and \, like: getEmbeddedData('V\\.1'), but both of those escape styles don't work - null is returned.
There is another syntax to access embedded data with javascript - the "${e://Field/myfield}" approach - but I need to be able to set the last character (i.e. the number after V) dynamically, and this method doesn't allow for that. Specifically, for embedded data V1:
var ix = 1;
Qualtrics.SurveyEngine.getEmbeddedData('V'+ix); <-- this works
"${e://Field/V"+ix+"}"; <-- this doesn't work
I have over 1000 fields that get imported from this contact list, so I don't want to rename each one by hand to remove the dots. It seems weird that Qualtrics would pick this naming schema as an import default if it breaks one of its own methods - am I doing something wrong here? Is there an alternate syntax I can use?
I answered your related question on the Qualtrics Community. You can't do "${e://Field/V"+ix+"}" because pipes are resolved on the server before the page is sent to the browser.
When a web service returns json or xml, by default Qualtrics uses a dot for each level in structure. You can override this by changing the embedded variables (on the left in the web service block) to names without dots.
Another alternative would be to write your own web service script that calls the Qualtrics API, then puts the results in a flat json structure before returning them to your survey.
Update based on comments below
Automatically renaming embedded variables returned from a web service call - I think the only way to do that is my alternative suggestion - write your own web service script that converts the info returned from the api and renames the variables putting them in a one dimensional associative array, then convert that array to json.
Qualtrics Question API - getEmbeddedData() has been removed from the documentation. I don't know why, and would have to ask Qualtrics Support. For now, it still works. So, if you need to construct embedded variable names with a dot dynamically, you could create your own function based off getEmbeddedData(). Use your browser's developer tools to see what it does.
I've found addEmbeddedData() to be useless in actual practice. setEmbeddedData() works whether the embedded data field is defined in the survey flow or not. If it is defined in the survey flow, it gets saved to the response data. If it is not defined in the survey flow, it can be referenced throughout the current survey response, but it won't be saved in the response data.
Related
Please see react final form's docs here
I'm working on a form which obviously is powered by react final form. In the form component, I'm fetching data from an API server and the response body includes something like the following:
{
"configs": {
"name": "abc",
"display.name": "Abc",
"value": 12,
"read.only": true
}
}
As we can see that there are four different key/value pairs in the configs. react final form can display values like name and value just fine but not values like display.name and read.only since they have a dot -> . in their key.
I know I can change these dots (.) with something like underscores and it will work. But the problem is that our backend devs are saying that using dots (.) to separate key names is very common in the backend so replacing dots with other separators won't be an option.
I'm currently replacing these separators with underscores in the frontend but that logic is everywhere and I think there should a better way to solve this. Thanks!
I think the answer is that Final Form just doesn't support keys with dots. Final Form needs some way to know when to go a level deeper into the form values object.
The only solution I could imagine would be to somehow tell Final Form to use another character (similar to how you can choose a different "divider" character when doing search-and-replace in VIM) as the "dot". So you could refer to your display name as <Field name="configs/display.name" delimiter="/"/>, but this feels like a pretty extreme edge case.
Longer term, I'd like to allow providing a type-safe get/set lens for each field, which would also solve this problem.
Wish I had better news for you... đ˘
Since you are locked with both a rigid backend naming and Final Form dotkey nested notation, unless you can change one of these two parameters I guess replacing dots with underscore is still the easiest solution.
This is really not about coding itself, as there is basically 3 cases :
Getting rid of Final Form and finding a new one, this could be costy especially if you have multiple devs working on this project. The cost of learning a new syntax, added to the complexity of handling new edge case is not worth it IMO.
Writing a custom view from your backend. You could ask your backend dev to develop a custom viewset for forms so they can keep their dot notation internally. This is usually a bad idea since it could easily create a technical debt, with a side of the dev team not knowing why a particular method exists.
The best is still what you did. Since frontend requires a special response format, it is frontend concern to adapt to what the backend sends, hence creating a custom middleware function that you apply to every incoming responses such as :
const JSONMiddleware = input => (
Object.entries(input).reduce((ac, cv) => {
const newKey = cv[0].replace('.', '_')
ac[newKey] = cv[1]
return ac
}, {})
)
This is probably not optimal in terms of user experience but it is easier to maintain since the problem and its solution are in the same scope of development.
I want to receive data from JavaScript file using PHP in Firebase in following structure.
Not like this.
From how I understood your question, I think you're looking to have your data to be added with an auto-generated Firebase id. So I think what you're looking for is the push() method:
Generates a new child location using a unique key and returns its Reference.
This is the most common pattern for adding data to a collection of items.
If you provide a value to push(), the value will be written to the generated location. If you don't pass a value, nothing will be written to the Database and the child will remain empty (but you can use the Reference elsewhere).
The unique key generated by push() are ordered by the current time, so the resulting list of items will be chronologically sorted. The keys are also designed to be unguessable (they contain 72 random bits of entropy).
Also see Firebase Database: Read and Write Data on the Web - Update specific fields.
I have a question about how to approach a certain scenario before I get halfway through it and figure out it was not the best option.
I work for a large company that has a team that creates tools for the team mates to use that arenât official enterprise tools. We have no access to the database directly, just access to an internal server to store our files to run and be able to access the main site with javascript etc (same domain).
What I am working on is a tool that has a ton of options in it that allow you to select that I will call âdata pointsâ on a page.
There are things like âAccount status, Balance, Name, Phone number, email etcâ and have it save those to an excel sheet.
So you input account numbers, choose what you need and then using IE Objects it navigates to the page and scrapes data you request.
My question is as follows..
I want to make the scraping part pretty Dynamic in the way it works. I want to be able to add new datapoints on the fly.
My goal or idea is so store the regular expression needed to get the specific piece of data in the table with the âdata point optionâ.
If I choose âNameâ it knows the expression for name in the database to run again the DOM.
What would be the best way about creating that type of function in Javascript / Jquery?
I need to pass a Regex to a function, have it run against the DOM and then return the result.
I have a feeling that there will be things that require more than 1 step to get the information etc.
I am just trying to think of the best way to approach it without having to hardcode 200+ expressions into the file as the page may get updated and need to be changed.
Any ideas?
IRobotSoft scraper may be the tool you are looking for. Check this forum and see if questions are similar to what you are doing: http://irobotsoft.org/bb/YaBB.pl?board=newcomer. It is free.
What it uses is not regular expression but a language called HTQL, which may be more suitable for extracting web pages. It also supports regular expression, but not as the main language.
It organizes all your actions well with a visual interface, so you can dynamically compose actions or tasks for changing needs.
I'm writing a bit of javascript for a web-based medical game (basically very new to javascript, but I have experience with Java, and I've just been picking things up as I go). The idea is that each case (patient) has several fields of data, and the names of the fields are always the same ("Heart Rate", "Chest X-Ray", etc), but the data associated with the names depend on the specific case. In just building the basic functionality, I've been using an associative array, so when someone enters an element (say, "Blood Test A"), the results appear in another area of the screen.
So, when I start creating cases, I'd like to have each case be a separate file on the server side which just stores the array so I can load the array at the beginning of the case and use the general references (which all the arrays have) to get the specific values stored in the specific array. I guess the other option would be to have a single file with multiple versions of the array and somehow pass the specific array back to the page's script and write it to a local variable.
Thoughts? Thanks!
It sounds like you just want to store your arrays as JSON which you can directly load using the client, for example:
patientA.json:
{
"Heart Rate": 160,
"Chest xray": ... whatever
}
Put that file on your webserver, then your client can do (using jQuery, for example)
$.getJSON("server_addr/patientA.json", function (data) { // do something with data } );
I have read a lot about parsing JSON with Actionscript. Originally it was said to use this library. http://code.google.com/p/as3corelib/ but it seems Flash Player 11 has native support for it now.
My problem is that I cannot find examples or help that takes you from beginning to end of the process. Everything I have read seems to start in the middle. I have no real experience with JSON so this is a problem. I don't even know how to point ActionScript to the JSON file it needs to read.
I have a project with a tight deadline that requires me to read twitter through JSON. I need to get the three most recent tweets, along with the user who posted it, their twitter name and the time those tweets were posted.
The back end to this is already set up I believe by the development team here, therefor my JSON files or XML just needs to be pointed to and then I need to display the values in the interface text boxes I have already designed and created.
Any help will be greatly appreciated...I do know that there are a lot of threads on here I just do not understand them as they all have some understanding of it to begin with.
You need to:
Load the data, whatever it is.
Parse the data from a particular format.
For this you would normally:
Use URLLoader class to load any data. (Just go to the language reference and look into example of how to use this class).
Use whatever parser to parse the particular format that you need. http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/JSON.html this is the reference to JSON API, it also shows usage examples. I'm not aware of these API being in production version of the player, still there might be quite a bit of FP 10.X players out there, so I'd have a fallback JSON parser, but I would recommend using this library: http://www.blooddy.by/en/crypto/ over as3corelib because it is faster. The built-in API are no different from those you would find in browser, so if you look up JSON JavaScript entries, the use should be in general similar to Flash.
After you parse JSON format, you will end up with a number of objects of the following types: Object, Array, Boolean, Number, String. It has also literals to mean null and undefined. Basically, you will be working with native to Flash data structures, you only should take extra care because they will be dynamically constructed, meaning you may not make assumption about existence of parts of the data - you must always check the availability.
wvxvw's answer is good, but I think skips over a to be desired explanation of what JSON itself is. JSON is plain text, javascript object notation, when you read the text on screen it looks something like this
http://www.json.org/example.html
you can see a side by side JSON and XML (both plain text formats) essentially JSON is a bunch of name value pairs.
When you use JSON.parse("your JSON string goes here") it will do the conversions to AS3 "dynamic objects" which are just plain objects (whose properties can be assigned without previously being defined, hence dynamic). But to make a long story short, take the example you see in the link above, copy and paste the JSON as a string variable in AS3, use
var str:String = '{"glossary": {"title": "example glossary","GlossDiv": {"title": "S","GlossList": {"GlossEntry": {"ID": "SGML","SortAs": "SGML","GlossTerm": "Standard Generalized Markup Language","Acronym": "SGML","Abbrev": "ISO 8879:1986","GlossDef": {"para": "A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso": ["GML", "XML"]},"GlossSee": "markup"}}}}}';
var test:Object = JSON.parse(str);
method on the string, store it in a variable and use the debugger to see what the resulting object is. As far as I know there's really nothing else to JSON it's simply this format for storing data (you can't use E4X on it since it's not XML based and because of that it's slightly more concise than XML, no closing tags, but in my opionion slightly less readable... but is valid javascript). For a nice break-down of the performance gains/losses between AMF, JSON and XML check out this page: http://www.jamesward.com/census2/ Though many times you don't have a choice with regard to the delivery message format or protocol being used if you're not building the service, it's good to understand what the performance costs of them are.