Sheet API writing with javascript failing - ajax

i am trying to write to google sheet cell using ajax. The read code below is working fine:
var sheetId="MY_SHEET_ID";
var sheetName="MY_SHEET_Name";
var API_Key="MY_API_KEY";
xhr.open("GET","https://sheets.googleapis.com/v4/spreadsheets/"+sheetId+"/values/"+sheetName+"?key="+API_Key+"",true);
But the write code isnt:
var values = [["ABC"]];
xhr.open("PUT","https://sheets.googleapis.com/v4/spreadsheets/"+sheetId+"/values/"+values+"/"+sheetName+"!c2?key="+API_Key+"&valueInputOption=RAW",true);

Related

Is there any way to get google classroom form question insert title image URL

I want to get the image url which is inserted when create a question into the classroom form.
Below is the code through we get the title , choices if available but i am not able to get the image url which is insert under the question title.
function getCourse() {
var form = FormApp.openById(id);
var formResponses = form.getItems();
var type=formResponses[0].getType();
var title = formResponses[0].getTitle();
var image =formResponses[0].getImage();//no such method Logger.log(image);
}
That image is not available through the Forms Service, it's added through the /viewresponse source code which is generated some way by Google. You could get it by using the URL Fetch Service (UrlFetchApp).
Related
How can I scrape text and images from a random web page?
(javascript / google scripts) How to get the title of a page encoded with iso-8859-1 so that the title will display correctly in my utf-8 website?
var blob = questionType.getImage();
var b64 = blob.getContentType() + ';base64,'+ Utilities.base64Encode(blob.getBytes());
var html = "data:" + b64 ;

how to pass softcoded element to crm web resource script

I'm having trouble passing in the name of an element into a Dyanamics CRM web Resource javacript.
This code works:
function OnFormLoad()
{
var subGrid = window.parent.document.getElementById("Claims")
// do work
}
This code doesn't:
function OnFormLoad(GridName)
{
var subGrid = window.parent.document.getElementById(GridName)
// do work
}
How do I pass in the name of the element I want to work with?
Please refrain from using document.getElementById in Dynamics as it is not supported.
I believe you are trying to get GridContext and get Data from that Grid.
For Example on Account entity we have Contacts as Grid and then you wish to get data from that Grid.
I replicated the same on Account Entity (OnLoad) and get tried to get data from Contacts Grid.
When adding OnLoad event I have passed Grid name as Parameter as below.
I have added below onLoad Js on Account entity and was able to retrieve data from grid.
Note: I have added timeout because directly firing onload was not able to load complete page and then grid Name was not available.
function onLoad(executionContext,gridName){
setTimeout(function(){ getGridDatat(executionContext,gridName); }, 3000);
}
function getGridDatat(executionContext,gridName){
debugger
var formContext = executionContext.getFormContext();
var gridContext = formContext.getControl("Contacts"); // get the grid context
var myRows = gridContext.getGrid().getRows();
/*var myRow = myRows.get(arg);
var gridRowData = myRow.getData();*/
var firstRow =myRows.get(0).getData();
var firstRowAllAttributes = firstrow.entity.attributes.getAll()
var firstRowfirstAttributeValue = firstrow.entity.attributes.get(0).getValue()
}
If you want to perform some operation on change of data formGird then there is one more way to achieve this. Make your grid as Editable and then you can find Events for that gird as below and could perform your operations.

Google Map not Updating By Onchange Event In Dynamics 365

In Dynamics 365(version:8.2), I am loading google map using web resource and then trying to initiate google map by onchange event from CRM input field but it is showing error alert message:
ReferenceError: google is not defined at initMap
I got the solution by finding iframe and then call google map.like this:
var description = Xrm.Page.getAttribute('new_street').getValue();
// Get the HTML iFrame object.
var iFrame = Xrm.Page.ui.controls.get('WebResource_Map').getObject();
// Get the element from the iFrame.
var element = iFrame.contentWindow.document.getElementById('addr_line1');
var ifr = iFrame.contentWindow;
// Set the element's value.
element.value = description+' ';
I need help on this.
Here's how I would suggest you do it:
From your script that loads the google maps (Web Resource), get the form attribute values (address fields).
Whenever you need to refresh the map in case of any field change, just reload the web resource that's embedded on your form and it should automatically call the google maps again resulting in your new location being set.
You can call the reloadMapOnFieldChange() on change of the fields for which you want the map to be refreshed
function refreshWebResource(name) {
var _webResourceControl = Xrm.Page.getControl(name);
if(_webResourceControl!=null && _webResourceControl!="" && _webResourceControl!=undefined)
{
var _src = _webResourceControl.getSrc();
_webResourceControl.setSrc(null);
_webResourceControl.setSrc(_src);
}
}
function reloadMapOnFieldChange(){
refreshWebResource(<Name of your Map Web Resource>);
}

jqGrid getData from all page

I need to getdata from all pages in jqgrid
for which below code dont work
var allRowsInGrid = $('#grid').jqGrid('getRowData');
so tried this:
var allRowsInGrid = $("#grid").jqGrid('getGridParam', 'data');
which is working fine but all new data like edit done on any editable field is getting lost
i saw below link for similar issue
http://stackoverflow.com/questions/3307189/jqgrid-getdata-only-returns-data-for-current-page
please help

Ajax form and google conversions - the tricky part

For 2 weeks now i have tried to impliment the google conversion code to one of my ajax form landing page.
what i had in the ajax after success is
var google_conversion_id = **MYID**;
var google_conversion_language = "iw";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "**MYLABEL**";
var google_conversion_value = 0;
$.getScript( "http://www.googleadservices.com/pagead/conversion.js" );
i just didn't work. in firebug i could have seen the js loads after filling the form but no conversion on the page
now what i have ending up doing is adding iframe - hidden, to the success message after the ajax.
this is working but for me is not the right way i wanted to do it
can anyone confirm my code is ok, or help understanding way it didn't work?
I got it to work using a dirty hack.
document.write = function(text) {
$('#footer').append(text);
};
$.getScript( "http://www.googleadservices.com/pagead/conversion.js" );
This is not ideal but it works for me until they remove the document.write from their script.
The current version of google adwords snippet uses document.write (see line 14 of conversion.js) which does not work after your page is loaded. The way I solved my problem is to use an iframe as what you did.
Here are more discussions.
http://groups.google.com/group/adwords-help-advanced/browse_thread/thread/2ef3ee7dc5863e86?pli=1

Resources