Update the Copies Explainer

let spreadsheetId = ‘114hEvWFEbgwmk9TIF54m6bRM6Nb-anMXF4G4qN1cufY’;
let contractId = ‘226uAXY0YRUj-HMW5LQZ2YeeJgyDqmJTpnzRkGmFLch0’;

function makeCopy(id, name) {
let file = DriveApp.getFileById(id);
let copy = file.makeCopy(name);
return copy.getId();
}

function updateDoc(doc, edits) {
for (let edit of edits) {
doc.replaceText(edit[0], edit[1]);
}
}

function main() {
let sheet = SpreadsheetApp.openById(spreadsheetId);
let values = sheet.getRange(“A2:C5”).getValues();

for (let row of values) {
let copyId = makeCopy(contractId, row[0] + ’ Contract’);
let copy = Documentapp.openById(copyId);
var edits = [
[ ‘CLIENT’, row[0] ],
[ ‘FEE’, row[1] ],
[ ‘SERVICE’, row[2] ]
];
updateDoc = (copy, edits);
}
}

main();

Thanks @Grasshopper_Ben for your help!! And @hunain_yousuf see here:
image
Here in DocumentApp line you have missed italic capital in ‘‘App’’ pls change that as soon as possible as we cannot run the code because of that.

And next @Grasshopper_Ben?

let spreadsheetId = ‘114hEvWFEbgwmk9TIF54m6bRM6Nb-anMXF4G4qN1cufY’;
let contractId = ‘226uAXY0YRUj-HMW5LQZ2YeeJgyDqmJTpnzRkGmFLch0’;

function makeCopy(id, name) {
let file = DriveApp.getFileById(id);
let copy = file.makeCopy(name);
return copy.getId();
}

function updateDoc(doc, edits) {
for (let edit of edits) {
doc.replaceText(edit[0], edit[1]);
}
}

function main() {
let sheet = SpreadsheetApp.openById(spreadsheetId);
let values = sheet.getRange(“A2:C5”).getValues();

for (let row of values) {
let copyId = makeCopy(contractId, row[0] + ’ Contract’);
var copy = DocumentApp.openById(copyId);
var edits = [
[‘CLIENT’, row[0] ],
[ ‘FEE’ , row[1] ],
[ ‘SERVICE’ , row[2] ]
]
updateDoc(copy, edits)
}
}

main();

This is the very right code.

Took a minute to figure out what that was…:flushed:. I figured it out (had to literally put in the array set).

Thanks though!

  • V

Hey there. If you copy and paste the code that is not code-formatted, then your code will get messed up.

This is formatted:

let spreadsheetId = '114hEvWFEbgwmk9TIF54m6bRM6Nb-anMXF4G4qN1cufY';

This is not formatted:
let spreadsheet = ‘114hEvWFEbgwmk9TIF54m6bRM6Nb-anMXF4G4qN1cufY’;

You can take a look at my topic that teach everyone on formatting code.

Link to the code-formatting topic!

Thanks!
P :slightly_smiling_face:

HURRAY I HAVE FINISHED IT!!


Thanks All for your help!!

1 Like

image
Can anybody please tell me where I’ve went wrong?

Could you please help me out

let spreadsheetId = ‘114hEvWFEbgwmk9TIF54m6bRM6Nb-anMXF4G4qN1cufY’;
let contractId = ‘226uAXY0YRUj-HMW5LQZ2YeeJgyDqmJTpnzRkGmFLch0’;

function makeCopy(id, name) {
let file = DriveApp.getFileById(id);
let copy = file.makeCopy(name);
return copy.getId();
}

function updateDoc(doc, edits) {
for (let edit of edits) {
doc.replaceText(edit[0], edit[1]);
}
}

function main() {
let sheet = SpreadsheetApp.openById(spreadsheetId);
let values = sheet.getRange(“A2:C5”).getvalues();

for (let row of values) {
let copyId = makeCopy(contractId, row[0] + ’’);
var copy = DocumentApp.openById(copyId);
var edits = [
[‘CLIENT’, row[0] ],
[ ‘FEE’ , row[1] ],
[ ‘SERVICE’ , row[2] ]
];
updateDoc(copy, edits);
}
}

main();

Hi Rachana,

I can’t see your code because your code is not formatted. Try posting a screenshot of your code.

This one is formatted:

let code = 'This code is formatted.';

But not this:
let code = ‘This code is not formatted, and the website is turning the quotes mark to smart quotes.’;

And this:
let code = 'This code is formatted, but not well formatted.';

D :slight_smile:

Could you please help

Hi Rachana,

In JavaScript, there are 3 quotation marks to use: single quote ', double quotes " and backtick `.

In your code, you’re using “smart quotes”, which makes the text looks nice and fancy, but not used for programming. This could happen when you copy and paste the code that is not code-formatted.

This is code-formatted:

let code = 'This code is formatted.';

But not this:
let code = ‘This code is not formatted, and the website is turning the quotation marks into smart quotes.’;

Try delete all smart quotes that are around the text, then replace them with single quote, double quotes or backticks.

Hope this helps!
D :slight_smile:

This may help you

You have the correct code and have completed this puzzle but right now the output on the phone screen is not correct. Please take a look at this post. @balajietr got it correct. Hope this helps.

Best,
@Pummarin_The_gamer

Hey! can you please help…

Here’s a full working solution:
(Click or tap to reveal):

let spreadsheetId = '114hEvWFEbgwmk9TIF54m6bRM6Nb-anMXF4G4qN1cufY';
let contractId = '226uAXY0RUj-HMW5LQZ2YeeJgyDqmJTpnzRkGmFLch0';


function makeCopy(id, name) {
    let file = DriveApp.getFileById(id);
    let copy = file.makeCopy(name);
    return copy.getId();
}

function updateDoc(doc, edits) {
    for (let edit of edits) {
        doc.replaceText(edit[0], edit[1]);
    }
}

function main() {
    let sheet = SpreadsheetApp.openById(spreadsheetId);
    let values = sheet.getRange("A2:C5").getValues();

    for (let row of values) {
        let copyId = makeCopy(contractId, row[0] + ' Contract');
        let copy = DocumentApp.openById(copyId);
        var edits = [
            [ 'CLIENT' ,row[0] ],
            [ 'FEE' ,row[1] ],
            [ 'SERVICE' ,row[2] ],
            ];
        updateDoc(copy, edits);
        }
}
main();

I don’t understand. Here is my full code:
let spreadsheetId = ‘114hEvWFEbgwmk9TIF54m6bRM6Nb-anMXF4G4qN1cufY’;
let contractId = ‘226uAXY0YRUj-HMW5LQZ2YeeJgyDqmJTpnzRkGmFLch0’;

function makeCopy(id, name) {
let file = DriveApp.getFileById(id);
let copy = file.makeCopy(name);
return copy.getId();
}

function updateDoc(doc, edits) {
for (let edit of edits) {
doc.replaceText(edit[0], edit[1]);
}
}

function main() {
let sheet = SpreadsheetApp.openById(spreadsheetId);
let values = sheet.getRange(“A2:C5”).getValues();

for (let row of values) {
let copyId = makeCopy(contractId, row[0] + ’ Contract’);
var copy = DocumentApp.openById(copyId);
var edits = [
[‘CLIENT’, row[0] ],
[ ‘FEE’ , row[1] ],
[ ‘SERVICE’ , row[2] ]
]
updateDoc(copy, edits)
}
}

main();

let spreadsheetId = ‘114hEvWFEbgwmk9TIF54m6bRM6Nb-anMXF4G4qN1cufY’;
let contractId = ‘226uAXY0YRUj-HMW5LQZ2YeeJgyDqmJTpnzRkGmFLch0’;

function makeCopy(id, name) {
let file = DriveApp.getFileById(id);
let copy = file.makeCopy(name);
return copy.getId();
}

function updateDoc(doc, edits) {
for (let edit of edits) {
doc.replaceText(edit[0], edit[1]);
}
}

function main() {
let sheet = SpreadsheetApp.openById(spreadsheetId);
let values = sheet.getRange(“A2:C5”).getValues();

for (let row of values) {
let copyId = makeCopy(contractId, row[0] + ’ Contract’);
let copy = DocumentApp.openById(copyId);
var edits = [
[[
[ ‘CLIENT’, row[0] ],
[ ‘FEE’, row[1] ],
[ ‘SERVICE’, row[2] ]
]]
};
}

main();
What am I missing?

Hey when I copy and paste it it says that the starter code has been modified or removed