Select id from JSON - json

I'm currently designing an app to display some attributes of products I have in a pricelist which is stored in a Google Sheets spreadsheet and I want it to get that data and show it
I have a google script which extracts all the data from the spreadsheet and returns a JSON. It's published as a web app and stored in a non visible component "Web1"
What I don't know how to do is to work with that JSON and select a particular row based on an ID that I get from a barcode scanner
I want it to work like this:
Get a result from the barcode reader
Display the result from the barcode scan in a textbox "Código de barras"
Use that result to filter from a JSON which is extracted from the spreadsheet
Display the JSON attribute "name" in the textbox "Producto"
I currently have this:

The web component works asynchronously, which means, first send the Get request and after having received the response in the GotText event, then do the further processing.

Related

Getting a list of values from API Server

I am still learning about API fetching. I want to get a list of values instead of just one value.
I am currently calling this API https://www.omdbapi.com that returns a movie based off the name or id:
http://www.omdbapi.com/?t=nameOfMovie
When calling that url with something like 'batman' it returns one json value of one of the batman movies. How would I be able to fetch a list? Or would that be entirely up to the people who run the API?

Issue with body.replaceText() in Google Docs

I am populating a Google Doc template based on a Google Form submission. Upon submit, the program copies the template Google Doc, captures the first item from the Google Form which is always the person's name (because this is a required field), and then replaces {{Name}} in the new file with the entered name using:
var name = itemResponses[0].getResponse();
body.replaceText('{{Name}}', name);
That works correctly. But then I iterate through the rest of the item response and not all the items are required, so I use a lookup table in a Google sheet. The loop takes the item id in the item response and then looks up the text that the response will replace. Then the program does:
var textToReplace //this value is from column B in the Google Sheet lookup table
var newText //this value is the entered response from the Google Form
body.replaceText(textToReplace, newText);
When I do this, I am getting a "Exception: Invalid argument: searchPattern" error. Why are these two body.replaceText() functions different? They are both finding a variable with in double brackets in the Google doc, but it only works in one case.
And to be clear, this was previously working correctly for the last couple of months and only recently started to not work (maybe Google changed something??). My hypothesis is that it has to do with a regex pattern in the first parameter of replaceText.
The "searchPattern" error is a good clue, in certain circumstances, it tells us the value of "textTopReplace" is not a valid search pattern. Since the code hasn't changed, the lookup table in your spreadsheet, or the fields on the form probably have.
One of your lookups is returning a value that isn't a valid search pattern. Perhaps it is returning Null, or an empty string?
You can get more information by using console.log to log debug info to the stackdriver log interface provided by Google, like so:
console.log('text to replace: "'+textToReplace+'"'); //this value is from column B in the Google Sheet lookup table
console.log('value: "'+newText+'"'); //this value is the entered response from the Google Form
body.replaceText(textToReplace, newText);
Then, to view the logs, select "stackdriver logging" from the View menu.

how to update google chart dashboard dynamically when selecting an individual response from a google form response sheet e

I have a google form response sheet and I have created a separate tab for doing analysis on an individual response. Basically filling out a table which is then used to generate graphs and charts. Each time I need to do analysis on a single response, I have to change the formula to look at the specific response and then drag the formula down to update the whole table and which then creates a column chart in a separate sheet.
My question is- Is there any way I can simply select the response (like a button in the google chart dashboard sheet) which then looks at the response in the response sheet and updates the table in the separate sheet to give the graph accordingly?
I have not used any app script so far in my sheet for the dashboard? It is just a simple data validation method looking at the values from other sheet and gives the graph. Not sure if app script is the solution or any other solutions to work around this.
Help!!
Table to fill from google form:
Google Chart Dashboard:
You could use a query or "if" formulas to do what you are describing. Your query or if statement should point to a cell(s) which is have drop-down data validation lists, which when changed then alter your table, which in turn changes the graphs.
Example 1:
=query(Sheet!A:C,"SELECT A WHERE B ='"&D1&"'",0)
This query looks at the cell D1 and altered depending on its contents.
Example 2:
=if(D1="SOMETHING","DOSOMETHING","ORDOSOMETHINGELSE)
In this statement again D1 could be a cell that contains a drop-down list of variable data validation items.
Hope this helps

ServiceNow - JSON Web Service, display related tables

I'm working on a C# program that retrieves data from a ServiceNow database and converts that data into C# .NET objects. I'm using the JSON Web Service to return my data in JSON format.
What I want to achieve is as follows: If there is a relational mapping between a value (for
example: I have a table called Company, where CEO is not a TEXT field but an sys_id to a Employee Table) I want to be able to output that data not with an sys_id (or just displaying the name property by using the 'displayvariable' parameter) but by an object displayed in JSON.
This means that the value of a property should be an object in JSON instead of just a single value.
A few examples:
// I don't want the JSON like this
{"Company":{"CEO":"b181e841c9212c008aeb36850331fab2"}}
// Or by displaying the name of the sys_id table
{"Company":{"CEO":"James Henderson" }}
// I want the data as follows, so I can have all the data I need inside a single JSON record.
{"Company":{"CEO":{"name":"James Henderson", "age":34, "sex":"male", "office":"SBN Left Floor 23"}}}
From reading the documentation I couldn't find anything in the JSON Web Service that allowed me to display the information like this nor
find any other alternative. It should have something to do with joining the tables and displaying it all in the right format.
I have been using SNC for almost three years and have not found you can automatically join tables in a web service. Your best option would be to use a scripted web service which possibly takes a query parameter and table parameter. Then you can json serialized your result as you see fit.
Or, another option would be to generate a new processor that will traverse the GlideRecord object. The ?JSON parameter you pass in to the URL is merely a flag to pass your request to a particular processor. Unfortunately the OOB one I believe is a Java class not a JS script, so you would need to write a script much like I mentioned earlier to traverse the object path serializing the object graph as far down as your want to go.

Displaying Album Info via JSON Facebook Graph API

I've been looking through the different threads on the Facebook Graph API and displaying the results via JSON. The examples are great but I only want to output the info for a particular album not loop through various results.
Here is a link to the Coca-Cola Wall Photos album. https://graph.facebook.com/99394368305
What I would like to do is display the Name of the Album and the Link.
Any help is much appreciated!
You can choose only the fields you want by specifying the fields query parameter:
https://graph.facebook.com/99394368305/?fields=name,link
From http://developers.facebook.com/docs/reference/api/#reading:
Selection
By default, most object properties are returned when you make a query. You can choose the fields (or connections) you want returned with the "fields" query parameter. For example, this URL will only return the id, name, and picture of Ben: https://graph.facebook.com/bgolub?fields=id,name,picture
You can also request multiple objects in a single query using the "ids" query parameter. For example, the URL https://graph.facebook.com?ids=arjun,vernal returns both profiles in the same response.