Which RadioButton in a group is checked (Google AppScript) - radio-button

Using Google AppScript. How could I find the checked RadioButton in a group? If it requires handler then with server one.
Many Thanks

there is an open issue on this but there is also a nice workaround ;-) (found by Romain Vialard, GAS TC)
here is a slightly modified version of his script adapted to run on a spreadsheet :
function radiotest() {
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();
var radioValue = app.createTextBox();
radioValue.setId("radioValue").setName("radioValue");
// var radioValue = app.createHidden().setName("radioValue") ;// choose the one you like
for(var i = 1; i < 10; i++){
var name = 'choice '+i;
var handler = app.createClientHandler().forTargets(radioValue).setText(name);
panel.add(app.createRadioButton('radioButtonGroup',name).addValueChangeHandler(handler));
}
panel.add(radioValue);
var Valide=app.createButton("Valide").setId("val");
panel.add(Valide)
app.add(panel);
//
var handler = app.createServerHandler("valide"); // this is the server handler
handler.addCallbackElement(radioValue)
Valide.addClickHandler(handler);
//
SpreadsheetApp.getActiveSpreadsheet().show(app);// show app
}
//
function valide(e){ ;// This function is called when key "validate" is pressed
var sh = SpreadsheetApp.getActiveSheet();
var RadioButton = e.parameter.radioValue;
sh.getRange('A1').setValue(RadioButton);
var app = UiApp.getActiveApplication();
return app;
}​
Note that the radioValue item can be either a textbox or a hidden text, both possibilities are in the script/

Related

Importing Gmail text to a specific Google Sheets

I receive everyday the same email from an app I've made. Those emails have the same text except for some numbers (for example 2 instead of 9). I'm trying to build a script that automatically compiles my Google Sheets report.
function myFunction() {
var thread = GmailApp.getUserLabelByName("").getThreads(0,1)[0]; // get first thread in inbox
var message = thread.getMessages()[0]; // get first message
Logger.log(message.getBody()); // log contents of the body
}
but it doesn't work.
What am I doing wrong?
The following script works for me. Note that due to the time it takes to execute and to stop duplicate results, I change the label after it is moved to the spreadsheet.
function myFunction() {
var ss = SpreadsheetApp.openById("Insert Sheet ID");
var sheet = ss.getSheetByName("Email Import");
var label = GmailApp.getUserLabelByName("Label");
var labelNew = GmailApp.getUserLabelByName("Label Moved");
var threads = label.getThreads();
for (var i=0; i<threads.length; i++)
{
var messages = threads[i].getMessages();
for (var j=0; j<messages.length; j++)
{
var sub = messages[j].getBody();
sheet.appendRow([sub])
}
threads[i].addLabel(labelNew);
threads[i].removeLabel(label);
}
}

Create memory index with Elasticsearch.net

I try to create memory index with following code but it creates regular index.
Any idea?
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node);
var client = new Elasticsearch.Net.ElasticsearchClient(settings);
var js = JsonConvert.SerializeObject("{settings: { index.store.type: memory}");
var index = client.IndicesCreate("sampleIndex", js);
Your second argument to the IndicesCreate method call is not correct. See the code below for a better way to achieve it. The first three lines are the same. In the fourth one, we properly create the settings for the index.
_body = new {
settings = new {
index = new {
store = new {
type = "memory"
}
}
}
};
var index = client.IndicesCreate("sampleIndex", _body);

getAllEntries() of NotesView in Domino To Go for Titanium returns null

If you have for example this code:
var db = new NotesDatabase("https://address.com/mobile.nsf", "Database");
var view = db.getView("PolicyData");
var vec = view.getAllEntries();
if(!vec) {
alert("nothing in view");
return;
}
var ve = vec.getFirstEntry();
it will fail because vec is null. Why?
The reason is that you need to synchronize the view with the Domino backend first, so that it's data is in the the local SQLite database of the device.
This would work:
var db = new NotesDatabase("https://address.com/mobile.nsf", "Database");
var view = db.getView("PolicyData");
var callback = function() {
var vec = view.getAllEntries();
if(!vec) {
alert("nothing in view");
return;
}
var ve = vec.getFirstEntry();
}
view.update(callback);
See http://www.youatnotes.com/web/youatnotes/wiki-dtg.nsf/dx/NotesView#Methods for more details about the update method.

Multiple HTTP Requests in WinRT / Win8

Is it possible to send more than two HTTP requests concurrently in WinRT? I'm trying to load multiple JSON documents from a server and HttpWebRequest fails to respond after the second call. Here is a sample snippet that illustrates this:
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
const string url = "http://www.bom.gov.au/fwo/IDV60901/IDV60901.94868.json";
const int iterations = 3;
var tasks = new List<Task>();
var ticks = DateTime.Now.Ticks;
for (var i = 0; i < iterations; i++)
{
// Create unique URL by appending a generated number.
var uniqueUrl = string.Format("{0}?v={1}", url, (i + ticks));
// Create the request.
var request = WebRequest.CreateHttp(uniqueUrl);
// Create the async task and store it for later.
var task = request.GetResponseAsync();
tasks.Add(task);
}
// Await all tasks in collection.
await Task.WhenAll(tasks);
Debugger.Break(); // <----- This will never break when iterations > 2
}
Put this code in a blank MainPage.xaml.cs and play around with the iterations value. If you set it to 2, then it works. Anything above that, it will fail.
NOTE :: Do not use Fiddler when testing this. Fiddler does something funny and it allows all these connections to go through. I don't know how nor why. You can test this yourself. If you run the code above with fiddler open, then success.
NOTE :: This is not real code. I'm only using this example to illustrate the issue.
I haven't tried using the WebClient API in WinRT, I've only used the HttpClient API (which I'm using quite extensively in my application).
This code works:
const string url = "http://www.bom.gov.au/fwo/IDV60901/IDV60901.94868.json";
const int iterations = 10;
var tasks = new List<Task<HttpResponseMessage>>();
var ticks = DateTime.Now.Ticks;
for (var i = 0; i < iterations; i++)
{
// Create unique URL by appending a generated number.
var uniqueUrl = string.Format("{0}?v={1}", url, (i + ticks));
var handler = new HttpClientHandler();
var client = new HttpClient(handler)
{
BaseAddress = new Uri(uniqueUrl)
};
var task = client.GetAsync(client.BaseAddress);
tasks.Add(task);
}
// Await all tasks in collection.
await Task.WhenAll(tasks);
It is a bit more tedious to get out the response body though as you need to do an async read of all the responses like so:
var responseTasks = tasks.Select(task => task.Result.Content.ReadAsStringAsync());
await Task.WhenAll(responseTasks);
Then you can iterate through the responseTask objects and take their result.

Set the value of custom webpart property in c#

How to set the value of custom webpart property Programatically in C#.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite SiteCollection = new SPSite(mySiteGuid))
{
SPWeb myWeb = SiteCollection.OpenWeb(myWebGuid);
myWeb .AllowUnsafeUpdates = true;
Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null;
mgr = myWeb.GetLimitedWebPartManager ("default.aspx",System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
foreach (System.Web.UI.WebControls.WebParts.WebPart myWebPart in mgr.WebParts)
{
if (myWebPart.Title == "Other Webpart Name")
{
myWebPart.Visible = ! myWebPart.Visible;
myWeb.Update();
break;
}
}
}
});
I have a custom property in the webpart of type string to get the input from the user.
I wanted to updated the value of the property from c#.
Is there any way to set the value?
TIA
Try myWebPart.Update() instead of myWeb.Update().
Maybe it's a bit late for the answer, but here i let a piece of code i used for this.
var webCollection = new SPSite("http://mySharePointSite").AllWebs;
foreach (SPWeb web in webCollection)
{
var landingPageReference = #"/Pages/default.aspx";
var page = web.GetFile(landingPageReference);
if (!page.Exists)
continue;
page.CheckOut();
var spLimitedWebPartManager = web.GetLimitedWebPartManager(page.ServerRelativeUrl, PersonalizationScope.Shared);
foreach (WebPart webPartItem in spLimitedWebPartManager.WebParts)
{
if (webPartItem.Title.Equals("myWebPartTitle"))
{
// Specify Properties to change here
webPartItem.ChromeType = PartChromeType.Default;
webPartItem.Description = "AGAIN CHANGED";
// Save made changes
spLimitedWebPartManager.SaveChanges(webPartItem);
break;
}
}
page.CheckIn("Add Comment if desired");
page.Publish("Add Comment if desired");
web.Update();
web.Dispose();
}