I have created a google form which I would like to convert to a template. The objective is to to distribute this template to other people so they can amend the form as they see fit. I also need these amended forms to sit inside a directory in the google drive.
How can I construct a google script to convert the original form into a template?
Thus far I have
var form = FormApp.openById('asdfasdfasdfasdfasdfasdfFORMIDGOESHEREfasdfasdfa');
I am stuck on how to take this form and now convert it to a template.
If you want to get the whole form and then transform it into a template to modify it at will, it is not feasible. But instead, if you want to get certain elements and modify them or create a new form using Apps Script you can check the Class Form, which gives you several methods that will allow you to insert or removes elements.
Related
Following on from this question - I am now unsure how I might be able to target certain paragraphs or elements within the document when using Google Apps Scripts in order to use the batch update method outlined one would need to find the range of the element that required styling.
If there were 10 empty paragraphs (with content of "\n",) in a document - how would it be possible to target the 8th paragraph and get the range values {"startIndex": xx, "endIndex": xx} relative to the document so they could be used in the batch update?
I have a feeling I am missing something very obvious here.
Using Google Docs API and the document ID you can make a documents.get request, which will return you a document resource with a body field which has a content field with all the elements in the document, where you can see the "startIndex" and "endIndex".
I tried two options for mail merge but I am not able to retain the formatting.
I don't want to save the email content in the HTML file of the code because I want it to be easy to update the email template for someone who does not know coding.
Using the regular mail merge code from google apps script where email content is stored in a cell of the sheet. But I want this content to be formatted - bullets, urls, bold etc.
Reference: https://developers.google.com/apps-script/articles/mail_merge
(Most effective so far) Using advanced version of regular mail merge but the variables cannot be formatted.
Refernce: https://developers.google.com/gsuite/solutions/mail-merge
Using a google doc template which has variables that will be filled from spreadsheet using a script. Then this content needs to be emailed without the formatting being lost. I am able to set the variables and send personalized emails, but the formatting (bold, bulleted list, new lines, urls) is being lost. How do I retain the formatting?
Reference : https://katydecorah.com/code/google-sheets-to-gmail-template/
Sample Doc Template
Hello {Name},
Here is your confirmation number {Number}.
Please bring the following items.
List item
List item
Please visit this website www.google.com for more details
The problem
I'm interested to know if it is possible to copy the entire contents of one Google Doc and paste into a comment in another Google Docs using keyboard commands.
Background-
I do a lot of grading of student papers and have a range of standard comments I use which are individually stored in separate documents. I use Macros and keyboard shortcuts in MS Word to grab the contents of the comment file I want and put it into a comment in the paper I'm grading. I edit the macro files using the VB editor when necessary. It works quite efficiently.
I found some related material in my research, however this don't quite match what I am trying to do.
I think the code from here Insert comment into Google doc does something like what I want, but kind of the opposite.
Google Apps Scripts is new to me. I'm not really looking to become a programmer, I just need to know if developing such a script is possible or not and how hard it would be. I would appreciate being pointed in the right direction. Thanks.
A sample to point you into the right direction:
function myFuction()
{
var fileOriginId='PASTE HERE THE ID OF THE FILE WITH THE COMMENT TEXT';
var fileDestinationId ='PASTE HERE THE ID OF THE FILE WHERE THE COMMENTS SHALL BE INSERTED';
var text=DocumentApp.openById(fileOriginId).getBody().getText()
var comment={ 'content': text};
Drive.Comments.insert(comment, fileDestinationId);
}
This code snippet passes the whole contents of a Google Docs document to the variable text. Subsequently, the contents of text is inserted as a comment into a second Google Docs document. It uses the Advanced Drive Service that needs to be enabled beforehand.
Should you desire to pass only a part of the text in the original file into the comment, e.g. a paragraph, you would need to chose the specific paragraph instead of the whole document body.
Should you desire to append the comment to a certain text within the destination document, you need to use the optional property context.value, as done in the reference you provided.
Please find here references to useful documentation that will help you
udderstand Apps Script and adjust the code snippet provided to your
requirements:
DocumentApp to access Google Docs documents
Body of a document
Retrieve children of a document
Advanced Drive Service
Enable Advanced Services
Insert comments with Advanced Drive Service
I am trying to get the value of an element attribute from this site via importXML in Google Spreadsheet using XPath.
The attribute value i seek is content found in the span class="item-chart_server-price__1r2rn".
outputs is 2,427 Z
Tried using:
//*[#id='app']/div[2]/div[2]/span[2] i get #N/A;
//div[#id='app']//div[#class='item-chart_item-chart__3YMlA']//div[#class='item-chart_server__37cgg']/span[#class='item-chart_server-price__1r2rn'] i get #N/A;
//span[#class='item-chart_server-price__1r2rn'] i get #N/A;
looks like this won't be possible. all you can get is:
=IMPORTXML("https://www.romexchange.com/?q=steel","//*")
Indeed, I was not able to fetch the data using ImportXML, but I ended up being able to fetch from romexchange.com using a custom javascript function.
You can have a look at it in
https://github.com/diogovk/rom_exchange_sheets_macro/blob/master/rom_exchange_sheets_macro.js
To enable it on your sheets, go to Tools->Script editor.
After you saved a new function ROMX_latest will be available.
I need a help. I am using Google App Scripts for creating Google Forms. How I can change form's color/palette?
I tried to find here https://developers.google.com/apps-script/reference/forms/, but nothing found.
For the moment you can't, FormApp works with the first version of Forms, so for the moment no templates available programmatically.
Last news on the subject here
I was facing the same issue here and found a workaround: create a "Template Form" with the proper theme you want, then you make a copy of it and do your coding to the new copied form.
The problem is, if you want to custom each form with a theme, it would need several template forms, and the code should be able to select the correct template. However, this is not my case. Here is a sample code:
var file = DriveApp.getFileById('your-template-form-id').makeCopy();
var form = FormApp.openById(file.getId());
Just make sure you remove the single question that is created within the template form if you're adding questions dinamically, else, add the questions you need.
Good to note that once you generate a form programmatically, you can then edit it just like a regular form. You get the link to the editable page from form.getEditUrl().