I'm trying to replicate the code from this page. When I deploy as web app, it brings up the user interface with the input boxes and submit button. However, when I click submit, it brings up this error message: "please select an active sheet first". When I bring up the UI in the spreadsheet itself, I get the same error. Instead of using openById I changed it to getActive.getSheetByName and it worked from the spreadsheet. However, going back to the web app, the new error message is now "Cannot call getSheetByName of null."
Can anyone suggest why I'm getting the "please select an active sheet first" error and what I need to do differently?
Here's the code I've copied, the only change I made was to put my SS key in the two appropriate places.
function doGet(e) {
var doc = SpreadsheetApp.openById("yyyy"); //I've got my SS key here
var app = UiApp.createApplication().setTitle('New app');
// Create a grid with 3 text boxes and corresponding labels
var grid = app.createGrid(3, 2);
grid.setWidget(0, 0, app.createLabel('Name:'));
// Text entered in the text box is passed in to userName
// The setName method will make those widgets available by
// the given name to the server handlers later
grid.setWidget(0, 1, app.createTextBox().setName('userName'));
grid.setWidget(1, 0, app.createLabel('Age:'));
grid.setWidget(1, 1, app.createTextBox().setName('age'));
// Text entered in the text box is passed in to age
grid.setWidget(2, 0, app.createLabel('City'));
grid.setWidget(2, 1, app.createTextBox().setName('city'));
// Text entered in the text box is passed in to city.
// Create a vertical panel..
var panel = app.createVerticalPanel();
// ...and add the grid to the panel
panel.add(grid);
// Create a button and click handler; pass in the grid object as a callback element and the handler as a click handler
// Identify the function b as the server click handler
var button = app.createButton('submit');
var handler = app.createServerHandler('b');
handler.addCallbackElement(grid);
button.addClickHandler(handler);
// Add the button to the panel and the panel to the application, then display the application app
panel.add(button);
app.add(panel);
return app;
}
// Function that records the values in a Spreadsheet
function b(e) {
var doc = SpreadsheetApp.openById("yyyy"); //I've got my SS key here
var lastRow = doc.getLastRow(); // Determine the last row in the Spreadsheet that contains any values
var cell = doc.getRange('a1').offset(lastRow, 0); // determine the next free cell in column A
// You can access e.parameter.userName because you used setName('userName') above and
// also added the grid containing those widgets as a callback element to the server
// handler.
cell.setValue(e.parameter.userName); // Set the value of the cell to userName
cell.offset(0, 1).setValue(e.parameter.age); // Set the value of the adjacent cell to age
cell.offset(0, 2).setValue(e.parameter.city); // set the value of the next cell to city
// Clean up - get the UiInstance object, close it, and return
var app = UiApp.getActiveApplication();
app.close();
// The following line is REQUIRED for the widget to actually close.
return app;
}
Thanks!
You are opening the spreadsheet and should open the sheet in the spreadsheet
sheet = doc.getSheetByName("sheet name")
The documentation
Related
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.
I have used the SideDrawer example and have a series of dropdown's on my SideDrawer. After the last selection I need to display details on the underlying page, in this case the homepage. How do I update the underlying page as a result of my selections.
Don't know where to start.
exports.installationIndexChanged = function (args){
const drawerComponent = args.object;
const sideDrawer = app.getRootView();
var context = sideDrawer.bindingContext;
var installation = drawerComponent.items[args.newIndex];
console.log(installation);
var installDD = drawerComponent.getViewById("installation");
var selectedInstall = installDD.selectedIndex;
appSettings.setNumber("id",(installDD.get("items").getValue(selectedInstall)));
}
the last line in the code above gets the ID of the record I need to display. I'm not sure if I can address the underlying page at this point, or need to know when the sidedrawer closes, display the record then. My preference would be to keep the sidedrawer open and display the record on the homepage first. The user can then close the sidedrawer to view the complete record.
I have been working on a project to transfer our daily records from 4 sheets in a spreadsheet to a master copy at the end of each day. I initially started with the master copy grabbing a copy but timed triggers became a headache so I then wanted to add a menu button to each daily sheet called "End of Day" so that when they had finished at close of business they pushed the button and it went out to the master sheet. So I got the menu item (as well as a 2nd one to check i knew what I was doing) then added the script into the first menu item but it doesn't seem to work properly. The sheet names are in the same order and named the same in both spreadsheets although I want the new range to be pasted in the 2nd column as I have a datestamp auto entered in the 1st column. I don't (at the moment need a sub header which is why I have // it out)
Any help would be greatly appreciated.
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('End of Day')
.addItem('Robins EOD', 'menuItem1')
.addItem('Huh', menuItem2)
// .addSeparator()
// .addSubMenu(ui.createMenu('Sub-menu')
// .addItem('Second item', 'menuItem2'))
.addToUi();
}
function menuItem1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var targSS = SpreadsheetApp.openById('1mHYT-_4VV89MEp5Bn9wQi4hCI_JZjN5XlZuqa2iDt8k');
var sheetNames = ['AM trip','PM trip','Pool / Beach','Night Dive'];
for(var i = 0; i < sheetNames.length; i ++){
var scrSheet = ss.getSheetByName(sheetNames[i]);
var targSheet = targSS.getSheetByName(sheetNames[i]);
var data = scrSheet.getRange('A7:U38').getValues();
targSheet.getRange(targSheet.getLastRow() + 1, 2 , data.length, data[0].length).setValues(data);
}
}
function menuItem2() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.alert('You clicked the second menu item!');
}
I have a Tridion Date control added to a GUI Extension .aspx page I have created.
I've added this to the ASPX page with
<c:Date id="AdjustDate" runat="server"
IsSeparateFields="false" AddClearButton="false" TabIndex="3"></c:Date>
and in my .JS I've added the following to
Give me a handle onto the Tridion Date Control (to select the date values etc.)
c.AdjustDate =
$controls.getControl($("#AdjustDate"),
"Tridion.Controls.Date")
Capture changes in the date (after the user selects OK in the modaldialog)
$evt.addEventHandler(c.AdjustDate, "change",
this.getDelegate(this._onHighlightDateChange));
I capture the event and perform some updates based on the date selected.
However, my GUI extension dialog is smaller in height than when the modal dialog is shown. I'd like to resize my ASPX dialog when the user clicks Select Date and the modal dialog is presented.
I've now captured the event of the user clicking the Select Date button
c.BtnDateSelect = $controls.getControl($("#AdjustDate_selectbutton"),
"Tridion.Controls.Button");
$evt.addEventHandler(c.BtnDateSelect, "click",
this.getDelegate(this._onDateButtonClicked));
However - I can't seem to access the height of the resulting dialog as I can't add any events to tie in
the opening of the dialog itself
the user clicking OK or Cancel (to adjust the height again) or
the modal dialog being closed
Am I missing events to tie into?
I've tried to create a handle to the OK button using
BtnDateOKSelect =
$controls.getControl($("html#DatePickerPopup.popup body center div#buttonContainer div#ButtonOk.tridion"),
"Tridion.Controls.Button");
but the reference (and variations of it) return undefined - possibly as this is in an iframe so the script can't access it?
Any pointers on working out what the events are I can tie into?
How to tie into those events (and when)?
Thanks
You cannot resize a dialog (modal) after it has been open. I wrote an extension where I had a similar problem, when my date picker was over my modal dialog, It look weird, so I made my dialog date picker bigger.
However I wasn't using a date picker control, but a regular html button. Here the code:
So I retrieve button and add the handler to show the date picker:
c.BtnStartDate = $controls.getControl($("#startDate"), "Tridion.Controls.Button");
$evt.addEventHandler(c.BtnStartDate, "click", this.getDelegate(this._onStartDateButtonClicked));
This is the code in the event:
SetDateRange$_onStartDateButtonClicked(event) {
this._setDate(event, "#startDate");
};
And the setDate function:
SetDateRange.prototype._setDate = function SetDateRange$_setDate(event, controlSelector) {
var p = this.properties;
var currentDate = new Date();
var c = p.controls;
p.datePickerPopup = $popup.create(
$cme.Popups.DATE_PICKER.URL, {
width: 550,
height: 350
},
{
date: currentDate,
popupType: Tridion.Controls.Popup.Type.MODAL_IFRAME
}
);
function SetDateRange$DatePicker$onPopupCanceled(event) {
if (p.datePickerPopup) {
p.datePickerPopup.dispose();
p.datePickerPopup = null;
}
}
function SetDateRange$DatePicker$onPopupSubmitted(event) {
var value = event.data.date;
if (value) {
var value = new Date(value);
value = $localization.getFormattedDateTime(value, Tridion.Runtime.LocaleInfo.fullDateTimeFormat);
jQuery(controlSelector).trigger('setdate', [value]);
}
p.datePickerPopup.dispose();
p.datePickerPopup = null;
}
$evt.addEventHandler(p.datePickerPopup, "unload", SetDateRange$DatePicker$onPopupCanceled);
$evt.addEventHandler(p.datePickerPopup, "submit", SetDateRange$DatePicker$onPopupSubmitted);
$evt.addEventHandler(p.datePickerPopup, "close", SetDateRange$DatePicker$onPopupCanceled);
p.datePickerPopup.open();
};
Again, it might not be the solution to your scenario, but this example shows how to open the date picker dialog and use the values it returns, without using the "Tridion Date Picker Control".
Hope this helps.
I have replaced the traditional select/option form elements with a nifty little popup window when a triggering image is clicked. The page is for accounting purposes and so multiple line items are to be expected. I've written the javascript that will dynamically generate new line item select/option elements. When the page loads, the initial set of choices loads and the user can click on them, get a pop up with some choices, choose one and then the box closes. The move to the next choice and so on and so forth. I've added livequery to my code for those dynamic elements. However... the livequery("click"...) seems to fire no matter where the user clicks on the page. Very frustrating.
I've read on here how great "live()" is in jQuery 1.3, but I am not able to upgrade fully to jquery 1.3 because a custom JS file depends on 1.2, so using live() is out of the question, however I have invoked the livequery() plugin and I really need to understand if I'm using it correctly.
I will post partial code. There's just way too much to post all of it.
Basically, I'm searching for divs starting with "bubble" and then a number afterwards. Then run the event on each them. Only bubble1 is static, 2 and up are dynamic. Am I missing the whole usage of livequery?
>$jb('div[id^="bubble"]').each(function () {
> var divid = $jb('div[id^="bubble"]').filter(":first").attr("id");
>var pref = "bubble";
>var i = divid.substring((pref.length));
>var trigger = $jb('#trigger' + i, this);
>var popup = $jb('#pop'+ i, this).css('opacity', 0);
>var selectedoption = $jb('selectedOption' + i, this);
>var selectedtext = $jb('selectedOptionText' + i, this);
>$jb([trigger.get(0), popup.get(0)]).livequery("click",
> function () {
>//alert(i);
// code removed for brevity (just the contents of the popups)
>});
Live works by using event delegation. A click event is attached to the body, and anytime something is clicked the selector is tested against the target. If it passes the selector test it calls the function (thus simulating a click event).
You probably want something like this:
$('div[id^="bubble"]').livequery("click", function() {
var divId = $(this).attr("id");
var i = divId.substring("bubble".length);
var trigger = $("#trigger" + i, this);
var popup = $("#pop" + i, this).css("opacity", 0);
// alert(i);
}