Google App Script - Can not insert group member - google-apps-script

I'm a beginner ok... I'm trying to get multiple values of a cell memberEmail, then insert to mail group.
But I got an error is Invalid Input: memberKey.
var groupMail = 'test#gmail.com';
var listUserMails = [];
var userMails = JSON.stringify(sheet.getRange(4, 9).getValue());
listUserMails = userMails.split("\\n");
for (var i = 0; i < listUserMails.length; i++) {
var userEmail = listUserMails[i];
var member = {
email: userEmail,
role: 'MEMBER'
};
member = AdminDirectory.Members.insert(member, groupMail);
}
Update:
When I log value of an array listMemberMails, it seems that the array I received contains only 1 string. It's not the 3 strings as expected.
["nguyen_tien_nghiep#gmail.com, nguyen_hai_ninh#gmail.com, vu_xuan_lam#gmail.com"]
<blockquote class="imgur-embed-pub" lang="en" data-id="a/hMd1ckO"></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>

Your problem comes from the JSON.stringify function. It assigns to the variable userMails the value
"nguyen_tien_nghiep#gmail.com\n nguyen_hai_ninh#gmail.com\n vu_xuan_lam#gmail.com"
whereby the doublequotes are considered part of the string. This is why, if you split userMails in three, it will give you the following three array entries:
listUserMails[0]: "nguyen_tien_nghiep#gmail.com
listUserMails[1]: nguyen_hai_ninh#gmail.com
listUserMails[2]: vu_xuan_lam#gmail.com"
You can easily confirm the latter by adding Logger.log(userEmail) inside of your for-loop. This is what inhibits you from creating three members with a valid email address (since only the second entry is a valid email address.
With this being said if you replace
var userMails = JSON.stringify(sheet.getRange(4, 9).getValue());
with
var userMails = sheet.getRange(4, 9).getValue();
and then adjust the separator to "\n" instead of "\n" your code should work correctly.
As a suggestion, you can debug your code by inserting logs (e.g. for listUserMails.length). This will help you to find errors.

Related

How can i do send bulk of list within one E-mail on App Script?

I am trying to do send an email that will go to the customer and he or she will see that which product has arrived in the office,
First, I am gathering the values from my Sheet like that (part of that code);
var partReceivedQuerySheet = uyg.getSheetByName("Part Received Query");
var partReceivedQuerySheetLastRow = partReceivedQuerySheet.getLastRow();
var indexSupplierName = partReceivedQuerySheet.getRange("A2:A"+partReceivedQuerySheetLastRow).getValues();
I am using the MailApp function, I want to send that email like table, for that reason I am using
HtmlBody, and my code like that (part of that code);
'<table>'+
'<tr>'+
'<td>'+indexSupplierName+'</td>'+
'</tr>
I tried for loop before MailApp function but that time it is sending number of suppliers name mails,
I tried the For loop before MailApp, but at that time it sent as many e-mails as the number of suppliers one by one.
Based on Ron M answer I did Supplier Names like my input. My code is;
var indexSupplierNames =partReceivedQuerySheet.getRange("A2:A"+partReceivedQuerySheetLastRow).getValues().flat();
var indexProductNames =partReceivedQuerySheet.getRange("B2:B"+partReceivedQuerySheetLastRow).getValues().flat();
var productInfoTable = '<table border="2"><tr><th><b>Brand</b></th>';
productInfoTable+='<th><b>Product Name</b></th>';
productInfoTable+='<th><b>Quantity</b></th>';
productInfoTable+='<th><b>Arrived to Warehouse?</b></th></tr>';
indexSupplierNames.forEach(supplierName=> {
productInfoTable+='<tr><td>'+supplierName+'</td></tr>'
});
productInfoTable+= '</table>';
I have Product Names, Quantity, and one more column on My Sheet, I want to add all to the table, but when I try that forEach() thing I can not align Product Names with Supplier Names.
Finally, the output that I want to like this. I am sorry about that, I am noobie in AppScript but I tried really so much and I could not add it.
Based on your expected output. The supplier names' should be written on a different table rows <tr></tr>
Here is a sample code:
var partReceivedQuerySheetLastRow = partReceivedQuerySheet.getLastRow();
var indexSupplierName = partReceivedQuerySheet.getRange("A2:A"+partReceivedQuerySheetLastRow).getValues().flat();
Logger.log(indexSupplierName);
var email = 'youremail';
var hmtlContent = '<table border="1"><tr><td><b>Brand</b></td></tr>';
indexSupplierName.forEach(name => {
hmtlContent += '<tr><td>'+name+'</td></tr>';
});
hmtlContent+='</table>';
Logger.log(hmtlContent)
MailApp.sendEmail(email,"Test","",{htmlBody: hmtlContent});
What it does?
I changed the Range.getValues() return from 2-d array into a 1-d array.
Created a starting html table content
Loop all supplier names. Append each name on a different row in the html table content
Output:
(Update:)
How to create and update the table with multiple columns:
var indexSupplierNames = ["Supplier1", "Supplier2", "Supplier3"];
var indexProductNames = ['Product1', 'Product2', 'Product3'];
var productInfoTable = '<table border="2"><tr><th><b>Brand</b></th>';
productInfoTable+='<th><b>Product Name</b></th>';
productInfoTable+='<th><b>Quantity</b></th>';
productInfoTable+='<th><b>Arrived to Warehouse?</b></th></tr>';
for (var i=0; i<indexSupplierNames.length; i++){
productInfoTable+='<tr><td>'+indexSupplierNames[i]+'</td><td>'+indexProductNames[i]+'</td><td>0</td><td>No</td></tr>'
}
productInfoTable+= '</table>';
Logger.log(productInfoTable);
MailApp.sendEmail("your#email.com","Test","",{htmlBody: productInfoTable});
Output:
Finally, I solved it like that thank you to Ron M for help me to learn.
Code;
productInfoTables = '<table border="2"><tr><th><b>Brand</b></th>';
productInfoTables+='<th><b>Product Name</b></th>';
productInfoTables+='<th><b>Quantity</b></th>';
productInfoTables+='<th><b>Arrived to Warehouse?</b></th></tr>';
for (var k=2;k<=partReceivedQuerySheetLastRow;k++){
var supplierNames = partReceivedQuerySheet.getRange(k,1).getValue();
var productNames = partReceivedQuerySheer.getRange(k,2).getValue();
var qty = partReceivedQuerySheet.getRange(k,3).getValue();
var arrivedToWarehouse = partReceivedQuerySheet.getRange(k,4).getValue();
productInfoTables+= '<tr<td>'+supplierNames+'</td>'+'<td>'+productNames+'</td>'+'<td>'+qty+'</td>'+'<td>'+arrivedToWarehouse+'</td></tr>'
}

Google html service to sheets

I'm not a big fan of google forms so I made the form for my user input in the html service. I found a way to push the data out of the form and into google sheets using all of my variables in the html file like this:
<textarea type="text" name="Special Instructions" id="instructions"></textarea>
...
var instructions = document.getElementById("instructions").value;
...
google.script.run
.formsubmit (instructions,...)
google.script.host.close()}
in combination with the following in the code file:
function formsubmit(instructions,...)
var ss = SpreadsheetApp.getActive().getSheetByName("Sheet1");
ss.getRange(ss.getLastRow(),7,1,1).setValue(instructions);
...
The problem is, not only is the code very slow to output results, but if I have more than 37 or so variables defined, it glitches out and rather than closing the dialog box and recording the values in a spreadsheet, it opens a blank web page.
I know there has to be better (and more efficient) way, but I'm afraid I don't know it.
On the "client side", put all of your variables into a JSON object or an array, the stringify it, and send that string to the server.
var objectOfData;
variableOne = "one";
variable2 = "two";
objectOfData = {};
objectOfData['varOne'] = variableOne;//Create a new element in the object
objectOfData['var2'] = variable2;//key name is in the brackets
objectOfData = JSON.stringify(objectOfData);//Convert object to string
google.script.run
.formsubmit(objectOfData);
And then convert the object as a string back to a real object:
function formsubmit(o) {
var arrayOfValues,k,myData,outerArray;
myData = JSON.parse(o);//Convert string back to object
var ss = SpreadsheetApp.getActive().getSheetByName("Sheet1");
arrayOfValues = [];
for (k in myData) {//Loop through every property in the object
thisValue = myData[k];//
Logger.log('thisValue: ' + thisValue);//VIEW the LOGS to see print out
arrayOfValues.push(thisValue);
}
outerArray = [];
outerArray.push(arrayOfValues);
ss.getRange(ss.getLastRow() + 1,7,1,arrayOfValues.length).setValue(outerArray);
...
Note that the last parameter of getRange('start row', start column, number of rows, number of columns) uses the length of the inner array named arrayOfValues. This insures that the parameter value will always be correct regardless of how the array is constructed.

Apps Script Utilities.parseCsv assumes new row on line breaks within double quotes

When using Utilities.parseCsv() linebreaks encased inside double quotes are assumed to be new rows entirely. The output array from this function will have several incorrect rows.
How can I fix this, or work around it?
Edit: Specifically, can I escape line breaks that exist only within double quotes? ie.
/r/n "I have some stuff to do:/r/n Go home/r/n Take a Nap"/r/n
Would be escaped to:
/r/n "I have some stuff to do://r//n Go home//r//n Take a Nap"/r/n
Edit2: Bug report from 2012: https://code.google.com/p/google-apps-script-issues/issues/detail?id=1871
So I had a somewhat large csv file about 10MB 50k rows, which contained a field at the end of each row with comments that users enter with all sorts of characters inside. I found the proposed regex solution was working when I tested a small set of the rows, but when I threw the big file to it, there was an error again and after trying a few things with the regex I even got to crash the whole runtime.
BTW I'm running my code on the V8 runtime.
After scratching my head for about an hour and with not really helpful error messages from AppsSript runtime. I had an idea, what if some weird users where deciding to use back-slashes in some weird ways making some escapes go wrong.
So I tried replacing all back-slashes in my data with something else for a while until I had the array that parseCsv() returns.
It worked!
My hypothesis is that having a \ at the end of lines was breaking the replacement.
So my final solution is:
function testParse() {
let csv =
'"title1","title2","title3"\r\n' +
'1,"person1","A ""comment"" with a \\ and \\\r\n a second line"\r\n' +
'2,"person2","Another comment"';
let sanitizedString =
csv.replace(/\\/g, '::back-slash::')
.replace(/(?=["'])(?:"[^"\\]*(?:\\[\s\S][^"\\]*)*"|'[^'\\]\r?\n(?:\\[\s\S][^'\\]\r?\n)*')/g,
match => match.replace(/\r?\n/g, "::newline::"));
let arr = Utilities.parseCsv(sanitizedString);
for (let i = 0, rows = arr.length; i < rows; i++) {
for (let j = 0, cols = arr[i].length; j < cols; j++) {
arr[i][j] =
arr[i][j].replace(/::back-slash::/g,'\\')
.replace(/::newline::/g,'\r\n');
}
}
Logger.log(arr)
}
Output:
[20-02-18 11:29:03:980 CST] [[title1, title2, title3], [1, person1, A "comment" with a \ and \
a second line], [2, person2, Another comment]]
It may be helpful for you to use Sheets API.
In my case, it works fine without replacing the CSV text that contains double-quoted multi-line text.
First, you need to make sure of bellow:
Enabling advanced services
To use an advanced Google service, follow these instructions:
In the script editor, select Resources > Advanced Google services....
In the Advanced Google Service dialog that appears,
click the on/off switch next to the service you want to use.
Click OK in the dialog.
If it is ok, you can import a CSV text data into a sheet with:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('some_name');
const resource = {
requests: [
{
pasteData: {
data: csvText, // Your CSV data string
coordinate: {sheetId: sheet.getSheetId()},
delimiter: ",",
}
}
]
};
Sheets.Spreadsheets.batchUpdate(resource, ss.getId());
or for TypeScript, which can be used by clasp:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('some_name');
const resource: GoogleAppsScript.Sheets.Schema.BatchUpdateSpreadsheetRequest = {
requests: [
{
pasteData: {
data: csvText, // Your CSV data string
coordinate: {sheetId: sheet.getSheetId()},
delimiter: ",",
}
}
]
};
Sheets.Spreadsheets.batchUpdate(resource, ss.getId());
I had this same problem and have finally figured it out. Thanks Douglas for the Regex/code (a bit over my head I must say) it matches up nicely to the field in question. Unfortunately, that is only half the battle. The replace shown will simply replaces the entire field with \r\n. So that only works when whatever is between the "" in the CSV file is only \r\n. If it is embedded in the field with other data it silently destroys that data. To solve the other half of the problem, you need to use a function as your replace. The replace takes the matching field as a parameter so so you can execute a simple replace call in the function to address just that field. Example...
Data:
"Student","Officer
RD
Special Member","Member",705,"2016-07-25 22:40:04 EDT"
Code to process:
var dataString = myBlob().getDataAsString();
var escapedString = dataString.replace(/(?=["'])(?:"[^"\](?:\[\s\S][^"\])"|'[^'\]\r\n(?:\[\s\S][^'\]\r\n)')/g, function(match) { return match.replace(/\r\n/g,"\r\n")} );
var csvData = Utilities.parseCsv(escapedString);
Now the "Officer\r\nRD\r\nSpecial Member" field gets evaluated individually so the match.replace call in the replace function can be very straight forward and simple.
To avoid trying to understand regular expressions, I found a workaround below, not using Utilities.parseCsv(). I'm copying the data line by line.
Here is how it goes:
If you can find a way to add an extra column to the end of your CSV, that contains the exact same value all the time, then you can force a specific "line break separator" according to that value.
Then, you copy the whole line into column A and use google app script' dedicated splitTextToColumns() method...
In the example below, I'm getting the CSV from an HTML form. This works because I also have admin access to the database the user takes the CSV from, so I could force that last column on all CSV files...
function updateSheet(form) {
var fileData = form.myFile;
// gets value from form
blob = fileData.getBlob();
var name = String(form.folderId);
// gets value from form
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.setActiveSheet(ss.getSheetByName(name), true);
sheet.clearContents().clearFormats();
var values = [];
// below, the "Dronix" value is the value that I could force at the end of each row
var rows = blob.contents.split('"Dronix",\n');
if (rows.length > 1) {
for (var r = 2, max_r = rows.length; r < max_r; ++r) {
sheet.getRange(r + 6, 1, 1, 1).setValue(String(rows[r]));
}
}
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange("A:A").activate();
spreadsheet.getRange("A:A").splitTextToColumns();
}
Retrieved and slightly modified a regex from another reply on another post: https://stackoverflow.com/a/29452781/3547347
Regex: (?=["'])(?:"[^"\\]*(?:\\[\s\S][^"\\]*)*"|'[^'\\]\r\n(?:\\[\s\S][^'\\]\r\n)*')
Code:
var dataString = myBlob.getDataAsString();
var escapedString = dataString.replace(/(?=["'])(?:"[^"\\]*(?:\\[\s\S][^"\\]*)*"|'[^'\\]\r\n(?:\\[\s\S][^'\\]\r\n)*')/g, '\\r\\n');

Create student roster from Classroom

I'm trying to pull the student information from a google classroom roster. Here is what I have so far:
function studentRoster() {
var optionalArgs = {
pageSize: 2
};
var getStudents = Classroom.Courses.Students.list("757828465",optionalArgs).students;
Logger.log(getStudents);
}
Sandy's answer below helped solve part of my problem and I get this as a log (names, id's, emails and such changed):
[16-01-05 17:44:04:734 PST] [{profile={photoUrl=https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg, emailAddress=jsdoe#fjuhsd.org, name={givenName=John, familyName=Doe, fullName=John Doe}, id=108117124004883828162}, courseId=757828465, userId=108117124004883828162}, {profile={photoUrl=https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg, emailAddress=jhdoe#fjuhsd.org, name={givenName=Jane, familyName=Doe, fullName=Jane Doe}, id=115613162385930536688}, courseId=757828465, userId=115613162385930536688}]
So my question now is: How do I extract only certain pieces of this information (like full name and email)?
The end result will be pushing it to a google sheet.
The Collection sections under the Classroom API Reference can help clarify some of the object chaining required to access the fields you want.
The following code will generate a list of student names, their email, and associated course ID.
function listStudents() {
var optionalArgs = {
pageSize: 0 // Max output
};
var response = Classroom.Courses.Students.list(xxxxxxxxx; // Put CourseID here
var students = response.students;
if(students && students.length > 0){
for( i = 0; i < students.length; i++){
var student = students[i];
// fullName is normally prefixed with s/ use of .substring removes first two characters
Logger.log('%s %s %s', student.profile.name.fullName.substring(2), student.profile.emailAddress, student.courseId );
}
} else {
Logger.log('No students in this course');
}
}
Collection courses.students
The Quickstart example is using the list method, and the list method takes optional query parameters. One of them being pageSize.
Query parameters for List
You are using the get method.
Documentation - Get method
The only options that the get method has is for the Path. And there is only one setting, the id.
So, that object literal named optionalArgs, you don't need for what you are doing. optionalArgs is an object because it has curly braces, and has elements that are "key/value" pairs. It's "literal", because it's typed into the code, as opposed to building the object with code.
If you did a search, (open the search dialog with Ctrl + F), and searched for optionalArgs, you'll see that it's not being used anywhere. So, the optionalArgs object with the pageSize property is not needed when using the get method.

prevent regex errors with unpredictable values

In a mail merge application I use the .replace() method to replace field identifiers by custom values and also in a reverse process to get the identifiers back.
The first way works every time since the replace first argument is a pretty normal string that I have chosen on purpose... but when I reverse the process it happens sometimes that the string contains incorrect regular expression characters.
This happens mainly on phone numbers in the form +32 2 345 345 or even with some accentuated characters.
Given I can't prevent this from happening and that I have little hope that my endusers won't use this phone number format I was wondering if someone could suggest a workaround to escape illegal characters when they come up ? note : it can be at any place in the string.
below is the code for both functions.
... (partial code)
var newField = ChampSpecial(curData,realIdx,fctSpe);// returns the value from the database
if(newField!=''){replacements.push(newField+'∏'+'#ch'+(n+1)+'#')};
//Logger.log('value in '+n+'='+realIdx+' >> '+Headers[realIdx]+' = '+ChampSpecial(curData,realIdx,fctSpe))
app.getElementById('textField'+(n+1)).setHTML(ChampSpecial(curData,realIdx,fctSpe));
if(e.parameter.source=='insertInText'){
body.replaceText('#ch'+(n+1)+'#',newField);
}
}
UserProperties.setProperty('replacements',replacements.join('|'));
cloakOn();
colorize('#ffff44');
return app;
}
function fieldsInDoc(e){
cloakOff();// remet d'abord les champs vides
var replacements = UserProperties.getProperty('replacements').split('|');
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
for(var n=0;n<replacements.length;++n){
var field = replacements[n].split('∏')[1];
var testVal = replacements[n].split('∏')[0];
body.replaceText(testVal,field);
}
colorize('#ffff44');
}
In the reverse process you are using the fieldvalues provided that can include regex special characters. you have to escape them before replacing:
body.replaceText(field.replace(/[[\]{}()*-+?.,\\^$|#\s]/, '\\$&'), '#ch'+(n+1)+'#');
This said, the "replace back the markers" a bad idea. What happens if two fields of the mail merge have the same value or the replacement text is already present in the document template...
One possible solution was to prevent the example fields in the doc from containing regex special characters so the replace had to occur in the forward process, not in the reverse (as suggested in the other answer).
Escaping these character in the fields values didn't work* so I ended up with a simple replacement by a hyphen (which make sense in most cases to replace a slash or a '+').
(*) the reverse process uses the value kept in memory so the escape sign was disturbing the replace in that function, preventing it to work properly.
the final working code goes simply like this :
//(in the first function)
var newField = ChampSpecial(curData,realIdx,fctSpe).replace(/([*+?^=!:${}()|\[\]\/\\])/g, "-");// replace every occurrence of *+?^... by '-' (global search)
About the comment stating that this approach is a bad idea I can only say that I'm afraid there is not really other ways to get that behavior and that the probability to get errors if finally quite low since the main usage of mail merge is to insert proper names, adresses, emails and phone numbers that are rarely in the template itself.
As for the field indicators they will never have the same name since they are numerically indexed (#chXX#).
EDIT : following Taras's comment I'll try another solution, will update later if it works as expected.
EDIT June 19 , Yesssss... found it.
I finally found a far better solution that doesn't use regular expression so I'm not forced to escape special characters ... the .find() method accepts any string.
The code is a bit more complex but the results is worth the pain :-))
here is the full code in 2 functions if ever someone looks for something similar.
function valuesInDoc(e){
var lock = LockService.getPrivateLock(); // just in case one clicks the second button before this one ends
var success = lock.tryLock(5000);
if (!success) {
Logger.log('tryLock failed to get the lock');
return
}
colorize('#ffffff');// this function removes the color tags on the field marlers
var app = UiApp.getActiveApplication();
var listVal = UserProperties.getProperty('listSel').split(',');
var replacements = [];
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var find = body.findText('#ch');
if(find == null){return app };
var curData = UserProperties.getProperty('selItem').split('|');
var Headers = [];
var OriHeaders = UserProperties.getProperty('Headers').split('|');
for(n=0;n<OriHeaders.length;++n){
Headers.push('#'+OriHeaders[n]+'#');
}
var fctSpe = 0 ;
for(var i in Headers){if(Headers[i].indexOf('SS')>-1){fctSpe = i}}
for(var n=0;n<listVal.length;++n){
var realIdx = Number(listVal[n]);
Logger.log(n);
var newField = ChampSpecial(curData,realIdx,fctSpe);
//Logger.log(newField);
app.getElementById('textField'+(n+1)).setHTML(ChampSpecial(curData,realIdx,fctSpe));
if(e.parameter.source=='insertInText'){
var found = body.findText('#ch'+(n+1)+'#');// look for every field markers in the whole doc
while(found!=null){
var elemTxt = found.getElement().asText();
var startOffset = found.getStartOffset();
var len = ('#ch'+(n+1)+'#').length;
elemTxt.deleteText(startOffset, found.getEndOffsetInclusive())
elemTxt.insertText(startOffset,newField);// remove the marker and write the sample value in place
Logger.log('n='+n+' newField = '+newField+' for '+'#ch'+(n+1)+'#'+' at position '+startOffset)
replacements.push(newField+'∏'+'#ch'+(n+1)+'#'+'∏'+startOffset);// memorize the change that just occured
found = body.findText('#ch'+(n+1)+'#',found); //loop until all markers are replaced
}
}
}
UserProperties.setProperty('replacements',replacements.join('|'));
cloakOn();
colorize('#ffff44');// colorize the markers if ever one is left but it shouldn't happen
lock.releaseLock();
return app;
}
function fieldsInDoc(e){
var lock = LockService.getPrivateLock();
var success = lock.tryLock(5000);
if (!success) {
Logger.log('tryLock failed to get the lock');
return
}
cloakOff();// remet d'abord les champs vides > shows the hidden fields (markers that had no sample velue in the first function
var replacements = UserProperties.getProperty('replacements').split('|');// recover replacement data as an array
Logger.log(replacements)
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
for(var n=replacements.length-1;n>=0;n--){ // for each replacement find the data in doc and write a field marker in place
var testVal = replacements[n].split('∏')[0]; // [0] is the sample value
if(body.findText(testVal)==null){break};// this is only to handle the case one click on the wrong button trying to place markers again when they are already there ;-)
var field = replacements[n].split('∏')[1];
var testValLength = testVal.length;
var found = body.findText(testVal);
var startOffset = found.getStartOffset();
Logger.log(testVal+' = '+field+' / start: '+startOffset+' / Length: '+ testValLength)
var elemTxt = found.getElement().asText();
elemTxt.deleteText(startOffset, startOffset+testValLength-1);// remove the text
// elemTxt.deleteText(startOffset, found.getEndOffsetInclusive() )
elemTxt.insertText(startOffset,field);// and write the marker
}
colorize('#ffff44'); // colorize the marker
lock.releaseLock();// and release the lock
}