I am using Google Script to create a form that will create an event, as you can see from the code I have used two panels. I want to create multiple event forms on the 'parent' panel, I am trying to use the 'child' to hold information about the event. I want to run createEvent() on each child panel, but when I run it the script will not run and show this error message:
"Error occured: InternalError: Cannot find method createEvent((class),(class),(class),object)."
function doGet(){
var app = UiApp.createApplication().setTitle('Create Events');
//Create a penel which holds all the form elelemnts
var parent = app.createHorizontalPanel().setId('parent');
var panelOne = app.createVerticalPanel().setBorderWidth(2);
var eventTitleLabel = app.createLabel('Event Title:');
var eventTitle = app.createTextBox();
var eventStartDateLabel = app.createLabel('Event Start Date:');
var evenStartDate = app.createDateBox();
var eventEndDateLabel = app.createLabel('Event End Date:');
var evenEndDate = app.createDateBox();
var eventDeatilLabel = app.createLabel('Event Details:');
var eventDetail = app.createTextArea().setSize('150', '100');
var eventButton = app.createButton('Create Events');
var cancelButton = app.createButton('Cancel');
panelOne.add(eventTitleLabel)
.add(eventTitle)
.add(eventStartDateLabel)
.add(evenStartDate)
.add(eventEndDateLabel)
.add(evenEndDate)
.add(eventDeatilLabel)
.add(eventDetail)
.add(eventButton)
.add(cancelButton);
var eventHandler = app.createServerClickHandler('createEvents');
eventHandler.addCallbackElement(parent);
//Add this handler to the button
eventButton.addClickHandler(eventHandler);
parent.add(panelOne);
app.add(parent);
app.close();
return app;
}
function createEvents(e){
//Get the active application
var app = UiApp.getActiveApplication();
try{
var eventTitle = e.parameter.eventTitle;
var eventStartDate = e.parameter.eventStartDate;
var eventEndDate = e.parameter.eventEndDate;
var eventDetails = e.parameter.eventDetail;
var cal = CalendarApp.getDefaultCalendar();
cal.createEvent(eventTitle, eventStartDate,eventEndDate,{description:eventDetails});
app.add(app.createLabel('Event created Successfully'));
app.getElementById('panel').setVisible(false);
return app;
}
catch(e){
app.add(app.createLabel('Error occured: '+e));
return app;
}
}
All the input widgets need a .setName() to be able to pass their values to the server function. https://developers.google.com/apps-script/guides/ui-service#ServerHandlers
Also consider using Logger.log() for debugging.
You simply forgot to set names to the widgets you want to get data from... in your example :
var eventTitleLabel = app.createLabel('Event Title:');
var eventTitle = app.createTextBox().setName('eventTitle');
var eventStartDateLabel = app.createLabel('Event Start Date:');
var evenStartDate = app.createDateBox().setName('evenStartDate');
var eventEndDateLabel = app.createLabel('Event End Date:');
var evenEndDate = app.createDateBox().setName('evenEndDate');
var eventDeatilLabel = app.createLabel('Event Details:');
var eventDetail = app.createTextArea().setSize('150', '100').setName('eventDetail');
Related
I came across an scenario where I have to clone my custom entity.
Then I have started doing using with JavaScript by placing a custom duplicate button in the ribbon which triggers my JavaScript.
I used the following code:
function duplicateOrder(primaryControl){
var formContext = primaryControl;
var city = formContext.getAttribute('new_city').getValue();
var country = formContext.getAttribute('new_country').getValue();
var state = formContext.getAttribute('new_state').getValue();
var postal_code = formContext.getAttribute('new_zipcodepostalcode').getValue();
// var formItem = formContext.ui.formSelector.items.get();
// alert(`the form item value is ${formItem}`);
formContext.data.entity.save('saveandnew');
sleep(3000);
var city1 = formContext.getAttribute('new_city').getValue();
var country1 = formContext.getAttribute('new_country').getValue();
var state1 = formContext.getAttribute('new_state').getValue();
var postal_code1 = formContext.getAttribute('new_zipcodepostalcode').getValue();
alert(`${city1},${country1},${state1},${postal_code1}`);
if(city1==null){
formContext.getAttribute('new_city').setValue(city);
}
if(country1==null){
formContext.getAttribute('new_country').setValue(country);
}
if(state1==null){
formContext.getAttribute('new_state').setValue(state);
}
if(postal_code1==null){
formContext.getAttribute('new_zipcodepostalcode').setValue(postal_code);
}
alert(`${city},${country},${state},${postal_code}`);
}
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
I tried using the save and new logic to open a new entity form.
The New entity form opens but the field values do not get copied in the new how.
Please help me how to solve this.
Thanks and advance!
You need to call Xrm.Navigation.openForm with your cloneid record.
// Load newly copy record
var entityFormOptions = {};
entityFormOptions["entityName"] = "stdseries";
entityFormOptions["entityId"] = cloneId;
// Open the form.
Xrm.Navigation.openForm(entityFormOptions).then(
function (success) {
formContext.data.refresh();
},
function (error) {
});
I'm getting an error when I try to run the following code in InDesign.
I'm actually getting this code directly from an Adobe tutorial, not sure why they'd get their own code wrong. Any way you could help would be greatly appreciated! Thanks.
try{myFont = app.fonts.item("Arial");
}
catch (myError){};
var myDocument = app.documents.item(0);
with(myDocument){
var myPage = pages.item(0);
var myBounds = myGetBounds(myPage,myDocument);
with(myDocument.pages.item(0)){
//Get a reference to the text frame.
var myTextFrame = textFrames.item(0);
//Change the size of the text frame.
myTextFrame.geometricBounds = myBounds;
var myParagraph = myTextFrame.paragraphs.item(0);
myParagraph.appliedFont = myFont;
myParagraph.justification = Justification.centerAlign;
myParagraph.pointSize = 48;
}
}
//myGetBounds is a function that returns the bounds
//of the "live area" of a page.
function myGetBounds(myDocument, myPage){
var myPageWidth = myDocument.documentPreferences.pageWidth;
var myPageHeight = myDocument.documentPreferences.pageHeight;
if(myPage.side == PageSideOptions.leftHand){
var myX2 = myPage.marginPreferences.left;
var myX1 = myPage.marginPreferences.right;
}else{
var myX1 = myPage.marginPreferences.left;
var myX2 = myPage.marginPreferences.right;
}
var myY1 = myPage.marginPreferences.top;
var myX2 = myPageWidth - myX2;
var myY2 = myPageHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
}
It looks like in the myGetBounds() function you are passing the arguments in the wrong order.
In the function definition you can see that the document should be passed first and then the page second, but in the line starting with var myBounds you do it the other way around.
So the line should probably be:
var myBounds = myGetBounds(myDocument, myPage);
I am developing a project with the Kendo UI Framework, using more specically the Scheduler widget and I have the current issue:
On my database I have two tables one called Events and the other one called TypeOfEvents. Each type of event has got a specific color, a specific title plus defined values for startHour and endHour fields.
When the pop-up window to create an event is called, I can choose on two kendoMultiSelect the correspondent user and the type of event.
I can also choose the startDate and endDate. The default behavior of a Scheduler widget has got two datetimepickers also, however, I don't want that option on my pop-up window because the events will have defined hours that an user can't change.
My idea would be the following one:
Once I click save after choosing a specific event on my MultiSelectList, there would be some way to concatenate the startHour and endHour values I have defined in my database with the startDate and endHour field that I choosed on the pop-up window.
Right now, all my events startDate/endDate fields are saved on my DB with this format: 2015-03-01 00:00:00.000
I would like to substitute all those zeros with the values I defined in advance in my startHour/endHour fields of my TypeOfEvents table.
Here's my current CREATE script:
create: function (createEvent) {
var typeOfEventID = $("#selectEvent").val();
var usernameID = $("#selectUsername").val();
var dataStartTemp = $("#dataStart").val();
var dataEndTemp = $("#dataEnd").val();
var note = $("#note").val();
var res = $("#customViewScheduler").data("kendoScheduler");
var res1 = res.resources[1].dataSource.data();
var dataStart = convertToJSONDate(dataStartTemp);
var dataEnd = convertToJSONDate(dataEndTemp);
var changeSet = [];
var id = 0;
usernameID.forEach(function (userID) {
typeOfEventID.forEach(function (eventID) {
var titletemp = $.grep(res1, function (elem) {
if (elem.TypeOfEventID == eventID) {
return true;
}
})
if (titletemp.length > 0) {
note = titletemp[0].title;
}
var entityChange = {};
entityChange.Id = id;
entityChange.Entity = {
'__type': "Events:#BlahBlahWeb",
'UsernameID': userID,
'TypeOfEventID': eventID,
'startDate': dataStart,
'endDate': dataEnd,
'Title': note
};
entityChange.Operation = 2;
changeSet.push(entityChange);
id++
})
})
var changesetPayload = JSON.stringify({
"changeSet": changeSet
});
//Create jQuery ajax request
var Params = {}
Params.type = "POST";
Params.url = "./../Services/BlahBlahWeb-BlahDomainService.svc/JSON/SubmitChanges";
Params.dataType = "json";
Params.data = changesetPayload;
Params.contentType = "application/json";
Params.error = function (httpRequest, textStatus, errorThrown) {
//SendErrorByEmail(errorThrown, httpRequest.responseText)
}
Params.success = function (data) {
//createEvent.success(data);
var scheduler = $("#customViewScheduler").data("kendoScheduler");
var elem = tratanewelem(data.SubmitChangesResult[0].Entity)
scheduler.dataSource.read();
}
//Make the ajax request
$.ajax(Params);
},
Any idea of how can I accomplish that?
Need a little help figuring out how to get 3 list boxes to populate based on the previous list box. So far what I have is 1 list box that populates from a spreadsheet. Can someone help me with setting up so that the 2nd listbox will populate based off the first and a 3rd listbox that will populate based off of the first listbox? Here is the code:
function doGet(e){
var app = UiApp.createApplication();
var mainPage = app.createVerticalPanel().setId('mainPage');
var dataItemsLB = app.createListBox().setId('dataItemsLB').setName('dataItemsLB');
var dataItemsLbl = app.createLabel('Data Items');
dataItems(dataItemsLB);
mainPage.add(dataItemsLB);
app.add(mainPage);
return app;
}
function dataItems(listbox){
var app = UiApp.getActiveApplication();
var ss = SpreadsheetApp.openById('0AhraBJOts4V3dDhYbERTR0hFNUtNdEhZd2c4OElpY0E');
var list = ss.getSheetByName('dataItems');
var values = list.getRange(1,1,ss.getLastRow(),1).getValues();
for (var i in values){
listbox.addItem(values[i][0].toString());
}
return app;
}
The code above is only for 1 listbox but I thought it would help me to start from the bottom so I understand any explanation.
Thanks for any advice!
Replied on community try this code:
function doGet(e){
var app = UiApp.createApplication();
var mainPage = app.createVerticalPanel().setId('mainPage');
var dataItemsLB = app.createListBox().setId('dataItemsLB').setName('dataItemsLB'); // create a basic list box
var dataItemsLB2 = app.createListBox().setId('dataItemsLB2').setName('dataItemsLB2'); // create a basic list box
var dataItemsLB3 = app.createListBox().setId('dataItemsLB3').setName('dataItemsLB3'); // create a basic list box
var dataItemsLbl = app.createLabel('Data Items');
dataItems(dataItemsLB); // call the "dataItems" function to populate the list box
// Create Server Handlers
var sHandlerLB = app.createServerHandler("listLBSelect");
sHandlerLB.addCallbackElement(mainPage);
dataItemsLB.addChangeHandler(sHandlerLB);
dataItemsLB2.addChangeHandler(sHandlerLB);
mainPage.add(dataItemsLB);
mainPage.add(dataItemsLB2);
mainPage.add(dataItemsLB3);
app.add(mainPage);
return app;
}
function dataItems(listbox){
var app = UiApp.getActiveApplication();
var ss = SpreadsheetApp.openById('0AhraBJOts4V3dDhYbERTR0hFNUtNdEhZd2c4OElpY0E');
var list = ss.getSheetByName('dataItems');
var values = list.getRange(1,1,ss.getLastRow(),1).getValues();
for (var i in values){
listbox.addItem(values[i][0].toString());
}
return app;
}
function listLBSelect(e) {
var app = UiApp.getActiveApplication();
Logger.log(e);
Logger.log("Listbox changed: " + e.parameter.source);
// check which listbox has been changed:
switch(e.parameter.source) {
case "dataItemsLB":
var dataItemsLB2 = app.getElementById("dataItemsLB2");
dataItemsLB2.addItem("aaaaaa");
dataItemsLB2.addItem("bbbbbb");
dataItemsLB2.addItem("cccccc");
break;
case "dataItemsLB2":
var dataItemsLB3 = app.getElementById("dataItemsLB3");
dataItemsLB3.addItem("hhhhhh");
dataItemsLB3.addItem("jjjjjj");
dataItemsLB3.addItem("kkkkkk");
break;
}
return app;
}
I have a simple, but problematic question.
Is there a way, using google script to send an argument to a mouseCallback?
Some examples are explained here, but each time the cell in written in the function.
I want this cell to change over time, and I need to pass a string to the callback.
This works
function foo() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication();
var button = app.createButton('submit');
app.add(button);
var handler = app.createServerClickHandler('b');
button.addClickHandler(handler);
doc.show(app);
}
function b() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var cell = doc.getRange('a1');
cell.setValue(Number(cell.getValue()) + 1);
var app = UiApp.getActiveApplication();
app.close();
// The following line is REQUIRED for the widget to actually close.
return app;
}
I would like something like this
function foo() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication();
var button = app.createButton('submit');
app.add(button);
var value = 'A1';
var handler = app.createServerClickHandler('b', value);
button.addClickHandler(handler);
doc.show(app);
}
function b(value) {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var cell = doc.getRange(value);
cell.setValue(Number(cell.getValue()) + 1);
var app = UiApp.getActiveApplication();
app.close();
// The following line is REQUIRED for the widget to actually close.
return app;
}
Can anyone help me in this?
Thanks !
There is answers to this question in here :
Thansk to google forum users :)
http://www.google.com/support/forum/p/apps-script/thread?fid=2ef3693fc9aee1050004ad903de88dd4&hl=en