google script - entire form delete - javascript

I want to send a form in Email to a group of 15 users. The form would contain just two questions one radial button with a pre-set long code and another one is yes and no. So creating form and emailing the form by doing it within Google Script is NOT the question here.
However, once users submit I want this form to be deleted. I know I can just do isAcceptingResponses() to false and let these old forms dust in my Google Drive. However, if I do that I will keep collecting irrelevant forms in my Google Drive. Is there anyway to destroy a form? or what would you suggest?
Here is an example of creating form as per Google developers manual
https://developers.google.com/apps-script/reference/forms/:
function myCreateForm() {
var form = FormApp.create('Form Autocreaticus');
var item = form.addCheckboxItem();
item.setTitle('What condiments would you like on your hot dog?');
item.setChoices([
item.createChoice('Ketchup'),
item.createChoice('Mustard'),
item.createChoice('Relish')
]);
form.addMultipleChoiceItem()
.setTitle('Do you prefer cats or dogs?')
.setChoiceValues(['Cats','Dogs'])
.showOtherOption(true);
form.addGridItem()
.setTitle('Rate your interests')
.setRows(['Cars', 'Computers', 'Celebrities'])
.setColumns(['Boring', 'So-so', 'Interesting']);
Logger.log('Editor URL: ' + form.getId());
return form.getId() //so I can later use for my myDeleteForm().
}
function myDeleteForm() { //myDeleteForm(formID) {
var formID = '1utQdu9EsuQFgMKNbP5Hjm68fxpP-_vKrBNNXL8jsOZo';
DriveApp.getFileById(formID).setTrashed(true);
}
*This code was changed to accommodate the functionality. Thank you!

To delete the file itself you may need to use the DriveApp. The methods you found only seem to remove/change settings or reponses.
This deletes:
function myDeleteForm() {
var formID = '1utQdu9EsuQFgMKNbP5Hjm68fxpP-_vKrBNNXL8jsOZo';
DriveApp.getFileById(formID).setTrashed(true);
}

Related

Best way to translate inputs

Good evening,
Today I've encountered a question/problem. I'll get right into it. So basically I have form which is used to create meal. Meal table (migration) looks like this:
$table->uuid('id')->primary();
$table->uuid('restaurant_id')->nullable();
$table->string('name_lt', 100);
$table->string('name_en', 100);
$table->string('name_ru', 100);
$table->smallInteger('prep_time');
$table->string('image', 150);
$table->boolean('visibility')->default(0);
$table->boolean('deleted')->default(0);
$table->timestamps();
$table->foreign('restaurant_id')->references('id')->on('restaurants')->onDelete('cascade');
Aside the there's tons of other stuff, like ingredients and stuff, which are related to that specific meal. In the form page I have 3 different forms for different languages that is my native lithuanian, english and russian. There is tab buttons for changing form to other language, all it does is just hide current form and show another (there is 3 identical forms in 1 page).
What I'm trying to achieve is if I fill in lithuanian language's inputs, I want english and russian inputs to be filled also (that can be achieved with jquery or javascript change function), but it should fill in translated text.
Simple example:
In first form I fill in text name_lt = 'Obuolys', so name_en and name_ru should get filled too, but in different language, in this case name_en = 'Apple', name_ru = 'яблоко'
I never used translation api's so I'm wondering what would be the best way, I'm thinking of using DeepL as it is quite cheap.
If someone could give me some advices or simple example would be nice, I could follow on from that.
If you want to use javascript, you could use a button's click event to fill out the other fields before submiting the form. If I understand it correctly you have 3 forms (1 per tab).
You could do something like this for each form.
<form id="form-lt" method="post">
#csrf
<input name="name_lt">
<input type="hidden" name="name_en">
<input type="hidden" name="name_ru">
{{-- Not a true submit button --}}
<button id="button-lt type="button">Submit</button>
</form>
Given a function that takes text input, the original language and the language you want to translate
async function translate(text, from_language, to_language) {
const response = await fetch(...);
const data = await response.json();
// get translated text from data
return translated_text;
}
The js part could look like this
const button_lt = document.getElementById('button-lt');
button_lt.addEventListener('click', async event => {
const form = event.target.form;
const lt_value = form.querySelector('[name=name_lt]').value;
const en_input = form.querySelector('[name=name_en]');
const ru_input = form.querySelector('[name=name_ru]');
en_input.value = await translate(lt_value, 'lt', 'en');
ru_input.value = await translate(lt_value, 'lt', 'ru');
form.submit();
});
Alternatively, if you want to do it server-side, you could try to call whatever translation API you end up using using the Http facade provided by laravel before validating the input data or before saving the model to the database.
Are you using PHP or javascript?
DeepL offers a NodeJS library (for the backend) and a PHP library to easily allow you to translate. For example, to translate in PHP, you can use the following snippet after installing the library:
$authKey = "f63c02c5-f056-..."; // Replace with your key
$translator = new \DeepL\Translator($authKey);
$result = $translator->translateText('Hello, world!', null, 'fr');
echo $result->text; // Bonjour, le monde!
To perform this when your users fill in some text, you will need to write the appropriate Laravel code. Please note that it is not safe to do this in the frontend, as it requires you to expose your $authKey.

Materialize Forms Accepting links

I use materialize often and ran into a little issue within one of my apps. To make it simple I want to basically include a link within a form input (materialize) that will send into a chat feature I made. When generating the tag, the form cannot read the text (because it is rejecting the html generated link format presumably). Does anyone knowledgable of forms with materialize know if forms can accept links and if so what kind of format or special script I would need to include to make the form accept text in the form of a link. It could be another issue as well. Any input would be appreciated!
Code in question:
// function for pre-filling the information in the modal on the chat button press
function handleChatForm() {
$.get("/api/user_data", {}, function(data) {
$('#sender-name').val(data.firstName);
$('.sender-name-label').addClass('active');
});
var currentChatNote = $(this).closest('.addedNoteRow').data("note");
console.log(currentChatNote);
console.log(currentChatNote.title);
var noteObjectForChat = {
title: currentChatNote.title,
body: currentChatNote.body
};
var noteLink = $('<a>');
noteLink.data('noteObject', noteObjectForChat);
noteLink.attr("href", "/cms");
noteLink.append(currentChatNote.title);
$('#new-message-body').val(noteLink)
$('.new-message-label').addClass('active');
}
/** Listener for send button to push data into firebase **/
sendButton.on('click', function() {
var msgName = nameInput.val().trim();
var msgText = textInput.val().trim();
myFirebase.push({ Name: msgName, Text: msgText });
textInput.val("");
});

Django: populate the field based on previous field value - missing the last step to make it work

Like many, I want to populate a field in a django form based on what is selected in another field. I've read alot of answers with javascript(I struggle in javscript, so that's where I'm having trouble with the exemples), and I almost got it working, but the last step(updating the field itself) isn't working so I'd love some help with that part.
Here are the 2 fields. The first fieldthat gets populated from a query and is located in a div named #merch in the form
merchandise = forms.ModelChoiceField(label='Merchandise', queryset=Merchandise.objects.all(),
merch_price = forms.DecimalField(label='Price', min_value=0, max_value=800,
initial='0.00',decimal_places = 2, max_digits=10)
Upon selection, the second field(div named #price) should then display the price based on the merchandise selected. I created the view for the ajax request:
def check_item_price(request):
if request.method == "GET":
item = request.GET.get('item', '0')#the zero as default doesn't seem to work. To verify
price = Merchandise.objects.get(id = item)
return JsonResponse(price.item_price, safe=False)#is it safe to turn safe off?
and the url
url(r'^_item_price', views.check_item_price, name='_item_price' )
Calling the url manually works great, it returns the price in json format
And here is the javascript that is in the html form. The first part works, upon change it calls the url and a json object is returned, but the second part that should update the second field isn't working. I admit my lack of knowledge in javascript is probably at fault here. I tried many variations based on examples, none worked for me.
<script type="text/javascript">
jQuery(document).ready(function() {
$('#merch').change(function() {
var item = $(this).find(':selected').val();
$.getJSON('/classes/_item_price/',{item:item},
function(data) {
$('#price').append("<option value=" + data.value + "></option>");
});
});
});
</script>
Any pointers on what to fix in the javascript?
Thanks!
After letting it marinate in my head for 2 months, I went back to it and finally made it work. Here is the right code
jQuery(document).ready(function() {
$('#merch').change(function() {
var item = $(this).find(':selected').val();
$.getJSON('/classes/_item_price/',{item:item},
function(data) {
document.getElementById('id_merch_price').value=data;
});
});
});
</script>
First, the ID wasn't precise enough, but also the way of updating it wasn't the right one it seems. I truly feel lost anytime I have to do research on javascript or jquery. So may ways to do the same thing, it's almost impossible to learn for a casual coder like me.

Accessing Other Entities Attributes in Dynamics CRM/365 Forms with javaScript

This function buttonBuzz() works inside the Forms of the Entities Account, Contacts and Leads. But not in the Opportunity form.
Mainly because there is no telephone1 attribute. There is however a Contact entity added with "Quick View" in a section with a telephonenumber inside.
I think it can be accessed with the telephone1 as well just not with Xrm.page
Any ideas how i can grab the attribute from inside the "quick view"?
I dont know if the "Quick view" window is a form of an iFrame. And if it is i have no clue how to access it with the Xrm.Page.getAttribute("telephone1").getValue();
function buttonBuzz(exObj) {
var phoneNumber;
// Here i store the "telephone1" Attribute from the current .page
phoneNumber = Xrm.Page.getAttribute("telephone1").getValue();
if (phoneNumber != null) { **Sends phonenumber** } ...
Quick Views display data from a record selected in a lookup field, in this case a Contact. You can query data from related records using the OData endpoint.
You first need to get the Guid of the record selected:
var contactId = Xrm.Page.getAttribute("parentcontactid")[0].id || null;
You would then need to send a SDK.REST request, passing parameters for the Id of the record (contactId), entityName and the columns:
var entityName = "Contact";
var columns = "Address1_Telephone1, FirstName, LastName";
SDK.REST.retrieveRecord(contactId, entityName, columns, null, function(result) {
// Success, logic goes here.
var address1_Telephone1 = result.Address1_Telephone1;
}, function(e) {
console.error(e.message);
});
As well as your JavaScript file, you would need to include the SDK.REST.js file that is included in the MS CRM SDK download within your Opportunity form libraries.
You can pull that field up from the Contact into the Opportunity by creating a Calculated Field, setting it equal to parentcontactid.telephone1
Put the field on the form, and you'll be able to .getAttribute() it like any other Opportunity field (being Calculated, it updates itself whenever the source changes).

Email an xml file using a generic button on a livecycle designer form?

I found the following script on another thread (13056369):
// Replace with actual path to the field which contains the subject:
var subject = form1.SF1.TxtFld1.rawValue.concat("_"+ form1.SF1.TxtFld2.rawValue);
var myDoc = event.target;
try {
myDoc.mailDoc({
bUI: false,
cTo: 'me#email.org', // Replace with actual receiver mail address.
cSubject: subject,
cSubmitAs: "PDF"
});
} catch (e) {
// exception handling...
}
The above works great. However, I would like to modify it to email the xml file instead of a pdf file. Any help on how to modify the above script would be greatly appreciated.
If you have another way that I can accomplish the same task, just let me know and I'll give it a try. I just need the subject line to use the two text fields identified in the above script, and the file needs to be xml not pdf.
I am using LiveCycle Designer 9.
var cSubLine = "Subject line";
var cBody = "Body of the email";
var cEmailURL = "mailto:theEmailYouWant#gmail.com?cc=" + "&subject=" + cSubLine + "&body=" + cBody;
event.target.submitForm({
cURL: cEmailURL,
cSubmitAs:"XML",
cCharSet:"utf-8"
});
You can use an email submit button instead of custom code to handle the parameters such as submission data type, email address and subject. This is a preferred approach rather than adding custom code in LiveCycle ES.
I did include an image of an email address button but cant post it since I'm a n00b to Stack Overflow. Do let me know if you have any other questions.

Categories

Resources