I'm trying to have users fill a form and I have the form all done here
https://docs.google.com/forms/d/1mjDLcGvcVlSG0Tjfx2ZEvGdrFqvQo-ezaB1A4vaBFK8/viewform
I have read through the answers here Upload an image to a Google spreadsheet
I have two issues:
How to call the form I have, rather than the one in this code
var submissionSSKey = 'google sskey';
var docurl = 'google form url'
var listitems = ['Gender','Male','Female']
var Panelstyle = {'background':'#dddddd','padding':'40px','borderStyle':'solid','borderWidth':'10PX','borderColor':'#bbbbbb'}
function doGet() {
var app = UiApp.createApplication().setTitle('Biodata').setStyleAttribute('padding','50PX');
var panel = app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(400, 200);
var title = app.createHTML('<B>89 Law School Class Alumni Biodata</B>').setStyleAttribute('color','grey').setStyleAttribute('fontSize','25PX');
var grid = app.createGrid(6,2).setId('grid');
var list1 = app.createListBox().setName('list1').setWidth('130');
for(var i in listitems){list1.addItem(listitems[i])}
var Textbox1 = app.createTextBox().setWidth('150px').setName('TB1');
var email = app.createTextBox().setWidth('150px').setName('mail');
var upLoad = app.createFileUpload().setName('uploadedFile');
var submitButton = app.createSubmitButton('<B>Submit</B>');
var warning = app.createHTML('Please fill in all fields').setStyleAttribute('background','#bbbbbb').setStyleAttribute('fontSize','18px');
//file upload
var cliHandler2 = app.createClientHandler()
.validateLength(Textbox1, 1, 40).validateNotMatches(list1,'Select a category').validateEmail(email).validateNotMatches(upLoad, 'FileUpload')
.forTargets(submitButton).setEnabled(true)
.forTargets(warning).setHTML('Now you can submit your form').setStyleAttribute('background','#99FF99').setStyleAttribute('fontSize','12px');
//Grid layout of items on form
grid.setWidget(0, 1, title)
.setText(1, 0, 'Category')
.setWidget(1, 1, list1.addClickHandler(cliHandler2))
.setText(2, 0, 'Name')
.setWidget(2, 1, Textbox1.addClickHandler(cliHandler2))
.setText(3, 0, 'Email')
.setWidget(3, 1, email)
.setText(4, 0, 'Image File')
.setWidget(4, 1, upLoad.addChangeHandler(cliHandler2))
.setWidget(5, 0, submitButton)
.setWidget(5, 1, warning);
var cliHandler = app.createClientHandler().forTargets(warning).setHTML('<B>PLEASE WAIT WHILE THE FILE IS UPLOADING<B>').setStyleAttribute('background','yellow');
submitButton.addClickHandler(cliHandler).setEnabled(false);
panel.add(grid);
app.add(panel);
return app;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
var ListVal = e.parameter.list1;
var textVal = e.parameter.TB1;
var Email = e.parameter.mail;
var fileBlob = e.parameter.uploadedFile;
var blob = fileBlob.setContentTypeFromExtension()
var img = DocsList.createFile(blob);
try{
var folder = DocsList.getFolder('photos');
}catch(e){DocsList.createFolder('photos');var folder = DocsList.getFolder('photos')}
img.addToFolder(folder);
img.removeFromFolder(DocsList.getRootFolder());
var weight = parseInt(img.getSize()/1000);
var sheet = SpreadsheetApp.openById(submissionSSKey).getSheetByName('Sheet1');
var lastRow = sheet.getLastRow();
var targetRange = sheet.getRange(lastRow+1, 1, 1, 4).setValues([[ListVal,textVal,Email,"https://drive.google.com/uc?export=view&id="+img.getId()]]);
var imageInsert = sheet.getRange(lastRow+1, 5).setFormula('=image("https://drive.google.com/uc?export=view&id='+img.getId()+'")');
sheet.setRowHeight(lastRow+1, 80);
var GDoc = DocumentApp.openByUrl(docurl)
GDoc.appendTable([['Category : '+ListVal,'Name : '+textVal,'Email : '+Email]])
var inlineI = GDoc.appendImage(img);
var width = inlineI.getWidth();
var newW = width;
var height = inlineI.getHeight();
var newH = height;
var ratio = width/height;
Logger.log('w='+width+'h='+height+' ratio='+ratio);
if(width>640){
newW = 640;
newH = parseInt(newW/ratio);
}
inlineI.setWidth(newW).setHeight(newH)
GDoc.appendParagraph('IMAGE size : '+width+' x '+height+' (eventually) resized to '+newW+' x '+newH+' for PREVIEW ('+weight+' kB) ');
GDoc.appendHorizontalRule();
GDoc.saveAndClose();
app.add(app.createLabel('Thank you for submitting'));
return app
}
I'm getting "Cannot read property "parameter" from undefined" when I run doPost(e)
Any idea what I should do, pls? I'm kinda behind schedule
Many thanks
in relation with your 2 questions :
You can't mix a form built with FormApp and a form built using UiApp, you'll have to build the entire form using UiApp if you want to keep the file upload feature as it is. As an alternative , you can of course build the entire form using HTMLService if you are more comfortable with html...
If you try to run the doPost function from the script editor you will always get an undefined value for e since e is actually the event info that holds all the elements returned by the doGet call (also known as callback element)
I've been looking at your form and I think it should be quite easy to transpose it in UiApp since all the fields are simple textBox elements. The post you used makes use of clientHandlers to make some fields mandatory so you have all the necessary informations to build your own form.
If you want to make it "look like" your form just change the style attributes of the panel and eventually add more style attributes to some items. Available CSS like styles are viewable here.
Related
I write a script to get a text file, to modify this texter file and then I import the file in our software.
The problem is that the import of the file is very slow (just this part of the script could take more than 1 minute sometime).
I would like to display a waiting gif during this process, so the user can see that the process is running, and he need to wait.
Some precision:
- It's only a javascript file with no html page
- The script is launched with a button in our software and I have access to ActiveXObject if necessary
Here is a sample code :
function importFec()
{
var iOpenDlg = 1;
var sPath = "Deskop";
var sTypes = "Fichier Texte (*.txt)|*.txt";
var sExt = "txt";
//Allow me to select a file in Windows
cheminFEC = fileDialog(iOpenDlg, sPath, sTypes, sExt);
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ForReading = 1;
var f1 = fso.OpenTextFile(cheminFEC, ForReading);
var texte = f1.ReadAll();
var tableauFEC = [];
var tableauTest = [];
tableauFEC = texte.split(/\r\n/);
tableauTest = tableauFEC[0].split("\t");
var delimiter = "\t";
if (tableauTest.length == 1)
{
tableauTest = tableauFEC[0].split("|");
var delimiter = "|";
}
var nbColonne = tableauTest.length;
for (var i=0;i<tableauFEC.length;i++)
{
var tab = tableauFEC[i].split(delimiter);
tableauFEC[i] = new Array(25);
for (var j=0;j<nbColonne;j++)
{
tableauFEC[i][j] = tab[j];
}
}
//Make some change in the table to adapt my texte file
//Then create a new texte file C:\\FichierFEC\\FECModifie.txt
createNewFEC(tableauFEC);
var cwfConfiguration = Application.ApplicationInfo("ProgramPath")+"\\Library\\ImportFEC\\ImportFEC23032017.vgl"
var oImport = Import(ipASCII)
oImport.ImportComponents = CWImportComponents.icGeneralLedger
oImport.ASCIILayoutFile = cwfConfiguration
oImport.ASCIIDataFile = "C:\\FichierFEC\\FECModifie.txt"
//This is the function which take a long moment to execute
oImport.RunImport()
}
Thanks for your answer and explanation
I finnaly found another solution.
At the beggining of my script, I launch a .hta file with a GIF and a small texte.
At the end of my script, I close the .hta file
Thanks
I have a gridview using devexpress tools that is populated on page load. When I select a row I have button that will allow me to edit the information in that row by popping up an edit box that allows me to change the information. The issue I am having is when they click that button the data that was behind the gridivew could have changed so I want to be able to query the database again (using some parameters from the selected row) when that edit button is clicked.
Here is the query that is ran when the 'edit' button is clicked.
function ShowPopupEditInventory() {
$.when(getFocusedInventory()).then(function (x) {
popupControlEditInventory.Show();
});
function getFocusedInventory(s, e) {
grid.GetRowValues(grid.GetFocusedRowIndex(), 'StorageLocation;LP;Sku_Alpha;LotCode;ExpirationDate;FIFOReferenceDate;ManufactureDate;InventoryStatus;SellableUnitQuantity;ReceiveDate;InventoryDetailID;Area', getFocusedInventoryValues);
}
function getFocusedInventoryValues(values) {
var fStorageLocation = values[0];
var fLP = values[1];
var fSku_Alpha = values[2];
var fLotCode = values[3];
var fExpirationDate = values[4];
var fFIFOReferenceDate = values[5];
var fManufactureDate = values[6];
var fInventoryStatus = values[7];
var fSellableUnitQuantity = values[8];
var fReceiveDate = values[9];
var fInventoryDetailID = values[10];
var fArea = values[11];
editInventoryStorageLocation.SetText(fStorageLocation);
editInventoryLP.SetText(fLP);
editInventoryItem.SetText(fSku_Alpha);
editInventoryQty_OldValue.SetText(fSellableUnitQuantity);
editInventorySts_OldValue.SetText(fInventoryStatus);
editInventoryLot_OldValue.SetText(fLotCode);
txtEditInventoryLot.SetText(fLotCode);
$(".editInventoryLot").val(fLotCode);
editInventoryStatus.SetValue(fInventoryStatus)
editInventoryUnitQuantity.SetText(fSellableUnitQuantity);
editInventoryDTL_No.SetText(fInventoryDetailID);
editInventoryNotes.SetText('');
$(".editInventoryAdjustmentCode").prop("selectedIndex", 0);
editInventoryArea.SetText(fArea);
editInventoryLot.Focus();
btnOKEditInventory.SetEnabled(true);
}
}
I want a Sharepoint 2013 app to create programmatically an Enterprise Custom Field when it runs for the first time.
I fiddled around with the following code snippet, but it's not working
var projContext = PS.ProjectContext.get_current();
function AddCustomField() {
$('#message').text('Adding Custom Field...');
var object_to_add = new PS.CustomFieldCreationInformation();
object_to_add.FieldType = CustomFieldType.Text;
object_to_add.Name = "New_one";
object_to_add.Description = "test description";
projContext.CustomFieldCollection.add(object_to_add);
}
Any help would be appreciated!
var projContext = PS.ProjectContext.get_current();
var fieldType = PS.CustomFieldType.TEXT;
var customfields = projContext.get_customFields();
var entityTypes = projContext.get_entityTypes();
var projEntity = entityTypes.get_projectEntity();
var resourceEntity = entityTypes.get_resourceEntity();
var taskEntity = entityTypes.get_taskEntity();
projContext.load(customfields);
projContext.load(entityTypes);
projContext.load(projEntity);
projContext.load(resourceEntity);
projContext.load(taskEntity);
projContext.executeQueryAsync(QuerySucceeded, QueryFailed);
CreateField("Test", "Test", fieldType, projEntity);
function CreateField(name, description, fieldtype, entitytype) {
var customfieldInfo = new PS.CustomFieldCreationInformation();
customfieldInfo.set_description(description);
customfieldInfo.set_name(name);
customfieldInfo.set_fieldType(fieldtype);
customfieldInfo.set_entityType(entitytype);
customfields.add(customfieldInfo);
customfields.update();
projContext.load(customfields);
projContext.executeQueryAsync(QuerySucceeded, QueryFailed);
}
I am using Google Scripts UiApp in order to gather availability information. I want to send this information to a spreadsheet. I have used the example here: http://www.googleappsscript.org/advanced-examples/insert-data-in-sheet-using-ui-forms
to get me started in the right direction.
The Web App looks good and when clicking submit, the appropriate message displays. However, the values that are transferred to the spreadsheet say "undefined" for all of the entries.
How can I convince it to link the textbox entered data to the variables so that I can transfer to the spreadsheet?
Thanks!!
Here is some code:
var submissioSSKey = // Key removed
function doGet() {
var rows = 15
var columns = 15
var mygrid = UiApp.createApplication().setTitle("MLC Walk Ins Scheduling")
var panel = mygrid.createSimplePanel();
// Define the grid layout
var grid = mygrid.createGrid(rows, columns).setCellPadding(2).setCellSpacing(8)
// Create the text at the top
var Title = mygrid.createLabel("Walk-In Scheduling")
grid.setWidget(1, 1, Title)
(snip) - creating various checkboxes and textboxes
var text1 = mygrid.createTextBox().setName('name1')
grid.setWidget(3,9,text1)
var text6 = mygrid.createTextBox().setName('message1')
grid.setWidget(4,9,text6)
// Create the "submit" button
var submit_button = mygrid.createButton("Submit")
grid.setWidget(12,9,submit_button)
var infoLabel = mygrid.createLabel('Availability inserted successfully.').setVisible(false).setId('info');
grid.setWidget(13,9,infoLabel)
var handler = mygrid.createServerClickHandler('insertInSS');
handler.addCallbackElement(panel);
submit_button.addClickHandler(handler);
panel.add(grid);
mygrid.add(panel);
mygrid.add(grid);
return mygrid
}
Then the function call for the button:
//Function to insert data in the sheet on clicking the submit button
function insertInSS(e){
var mygrid = UiApp.getActiveApplication()
var name1 = e.parameter.name1
var message1 = e.parameter.message1
mygrid.getElementById('info').setVisible(true).setStyleAttribute('color','blue')
var sheet = SpreadsheetApp.openById(submissioSSKey).getActiveSheet()
var lastRow = sheet.getLastRow()
var targetRange = sheet.getRange(lastRow+1, 1, 1, 2).setValues([[name1,message1]])
return mygrid
}
Ahh! A simple fix for a big headache.
I had an extra line:
mygrid.add(grid);
that was breaking it.
I am wondering how to add a duplicate panel underneath the previous existing panel ("productOtherPanel") using the "Add Product" button. I would like the new panel to be inserted below the existing "productOtherPanel" and above the "Add Product" button. I would also like this new panel to contain the same drop down list and text box as the original "productOtherPanel". I need this panel to duplicate an infinite number of times. Is this possible?
function doGet(e) {
var app = UiApp.createApplication();
var productOtherPanel = app.createHorizontalPanel().setId('productOtherPanel');
var productPanel = app.createVerticalPanel().setId('productPanel');
var productList = app.createListBox().setName("productList").setId('productList');
productList.addItem("8:1 Compressed Blocks");
productList.addItem("8:1 Compressed Briquettes");
var pricePerTonPanel = app.createVerticalPanel().setId('pricePerTonPanel');
var pricePerTonTextBox = app.createTextBox().setId("pricePerTonTextBox").setName("pricePerTonTextBox")
.setText("$0.00");
var buttonPanel = app.createVerticalPanel().setId('buttonPanel');
var button = app.createButton("Add Product");
app.add(productOtherPanel);
productOtherPanel.add(productPanel);
productPanel.add(productList);
productOtherPanel.add(pricePerTonPanel);
pricePerTonPanel.add(pricePerTonTextBox);
app.add(buttonPanel);
buttonPanel.add(button);
return app;
}
Try to see if this code is what you are looking for:
function doGet(e) {
var app = UiApp.createApplication();
var productOtherPanel = app.createVerticalPanel().setId('productOtherPanel');
var productPanel = app.createHorizontalPanel().setId('productPanel');
// Product list dropdown
var productList = app.createListBox().setName("productList").setId('productList');
productList.addItem("8:1 Compressed Blocks");
productList.addItem("8:1 Compressed Briquettes");
// Product Price Textbox
var pricePerTonTextBox = app.createTextBox().setId("pricePerTonTextBox").setName("pricePerTonTextBox").setText("$0.00");
productPanel.add(productList);
productPanel.add(pricePerTonTextBox);
var buttonPanel = app.createVerticalPanel().setId('buttonPanel');
var button = app.createButton("Add Product");
button.addClickHandler(app.createServerHandler("addProductHandler").addCallbackElement(productOtherPanel));
app.add(productOtherPanel);
productOtherPanel.add(productPanel);
app.add(buttonPanel);
buttonPanel.add(button);
return app;
}
function addProductHandler(e) {
var app = UiApp.getActiveApplication();
var productPanel = app.createHorizontalPanel().setId('productPanel');
// Product list dropdown
var productList = app.createListBox().setName("productList").setId('productList');
productList.addItem("8:1 Compressed Blocks");
productList.addItem("8:1 Compressed Briquettes");
// Product Price Textbox
var pricePerTonTextBox = app.createTextBox().setId("pricePerTonTextBox").setName("pricePerTonTextBox").setText("$0.00");
productPanel.add(productList);
productPanel.add(pricePerTonTextBox);
var panel = app.getElementById("productOtherPanel");
panel.add(productPanel);
return app;
}