var currDb:NotesDatabase = session.getCurrentDatabase();
var emailDoc:NotesDocument = database.createDocument();
var mailRTItem:NotesRichTextItem = emailDoc.createRichTextItem("Body");
var mStyle:NotesRichTextStyle = session.createRichTextStyle();
var r:NotesRichTextParagraphStyle = session.createRichTextParagraphStyle();
mStyle.setBold(1);
mailRTItem.appendStyle(mStyle);
mailRTItem.appendText(#Text("Dear Concerned,"));
mailRTItem.addNewLine(2);
r.setRightMargin(1);
mailRTItem.appendParagraphStyle(r);
mailRTItem.appendText("Text That is required to be right aligned");
emailDoc.save();
Replace your code line
r.setRightMargin(1);
with the line
r.setAlignment(NotesRichTextParagraphStyle.ALIGN_RIGHT);
This will set the right alignment.
Related
I have tried the below code, to split the latitude and longitude values, but its more complex. Is there any easy ways. Below shown is my code. I have used many replace functions as well split functions...
var data = [{"latitude":1.9,"longitude":103.57},{"latitude":1.338,"longitude":103.1},{"latitude":1.33,"longitude":103.7556}]
var re3 = /[\"\'\ ]+/g
data = data.replace(re3,'')
var re2 = /[\[\]\ ]+/g
data = data.replace(re2,'"')
var re1 = /[\'\r'\'\n'\{\ ]+/g
var data = data.replace(re1, '')
var re = /[\{\ ]+/g
var data = data.replace(re, '')
var re4 = /},/g
data = data.replace(re1, ';')
var re5 = /[\}\"\ ]+/g
data = data.replace(re, '')
let value = data.split(';');
console.log(value)
let valueArr = [];
value.forEach(geo => {
if (geo) {
let l = geo.split(',');
valueArr.push({
latitude: latLong[0],
longitude: latLong[1],
});
}
});
I would like to get output like
latitude: 1.9,
longitude: 1
and so on in the arr
03.57
That data seems to be in JSON format. Use JSON.parse().
var data = JSON.parse('[{"latitude":1.9,"longitude":103.57},{"latitude":1.338,"longitude":103.1},{"latitude":1.33,"longitude":103.7556}]');
console.log(data[0].latitude, data[0].longitude);
I've calculated the NDMI index based on the MCD43A4 (spatial resolution 500m) collection for an area where various water bodies exist.
What I want to do, is to mask out these water bodies from my collection, based on the Landsat Global Inland Water dataset (spatial resolution 30m),
but I have no idea how to do this.
The first thing I must do, is to change the spatial resolution of Landsat in order to match it with the MODIS one but I do not understand
how to this, should I use a type of Reduce?
Thanks
var geometry = /* color: #d63000 */ee.Geometry.Polygon(
[[[69.75758392503599, 50.151303763817786],
[71.60328705003599, 40.18192251959151],
[93.70777923753599, 41.54446477874571],
[91.86207611253599, 51.09912927236651]]]);
var dataset = ee.ImageCollection('GLCF/GLS_WATER')
.filterBounds(geometry)
.map(function(image){return image.clip(geometry)}) ;
var water = dataset.select('water');
var imageCollection = ee.ImageCollection("MODIS/006/MCD43A4")
.filterBounds(geometry)
.map(function(image){return image.clip(geometry)})
.filter(ee.Filter.calendarRange(6,8,'month'));
var modNDMI = imageCollection.select("Nadir_Reflectance_Band2","Nadir_Reflectance_Band6","BRDF_Albedo_Band_Mandatory_Quality_Band2","BRDF_Albedo_Band_Mandatory_Quality_Band6");
/////////////////////////////////////////////////
var quality = function(image){
var mask1 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band2").eq(0);
var mask2 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band6").eq(0);
return image.updateMask(mask1).updateMask(mask2);
};
var clean_collection = modNDMI.map(quality);
var addNDMI = function(image) {
var ndmi = image.normalizedDifference(['Nadir_Reflectance_Band2', 'Nadir_Reflectance_Band6']).rename('NDMI');
return image.addBands(ndmi);
};
var ndmi = clean_collection.map(addNDMI);
var NDMI=ndmi.select('NDMI')
print(water)
//And from this point, I have no idea how to mask the water bodies based on the
//Landsat collection
It's not entirely obvious what you mean by "mask the waterbodies," but if this is not what you intend, then just use water_mask.not().
var gsw = ee.Image('JRC/GSW1_0/GlobalSurfaceWater');
var occurrence = gsw.select('occurrence');
// Create a water mask layer, and set the image mask so that non-water areas
// are opaque.
var water_mask = occurrence.gt(90).unmask(0);
Map.addLayer(water_mask)
var dataset = ee.ImageCollection('GLCF/GLS_WATER')
var water = dataset.select('water');
var imageCollection = ee.ImageCollection("MODIS/006/MCD43A4")
.filterDate('2017-01-01', '2018-12-31')
.filter(ee.Filter.calendarRange(6,8,'month'));
var modNDMI = imageCollection.select("Nadir_Reflectance_Band2","Nadir_Reflectance_Band6","BRDF_Albedo_Band_Mandatory_Quality_Band2","BRDF_Albedo_Band_Mandatory_Quality_Band6");
var quality = function(image){
var mask1 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band2").eq(0);
var mask2 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band6").eq(0);
return image.updateMask(mask1).updateMask(mask2);
};
var clean_collection = modNDMI.map(quality);
var addNDMI = function(image) {
var ndmi = image.normalizedDifference(['Nadir_Reflectance_Band2', 'Nadir_Reflectance_Band6']).rename('NDMI');
return image.addBands(ndmi).updateMask(water_mask);
};
var ndmi = clean_collection.map(addNDMI);
var NDMI=ndmi.select('NDMI')
Map.addLayer(NDMI)
See also this tutorial.
I have the following xml:
<foo><toReplace/></foo>
I want to replace <toReplace/> tag with the following string:
"<b>bar</b>"
How can I do that?
Right now I have the following code:
var xml = "<foo><toReplace/></foo>";
var parser = new dom.DOMParser().parseFromString(xml, "text/xml");
parser.getElementsByTagName("toReplacce")[0].textNode = "<b>bar</b>";
console.log(parser.toString()); // "<foo><b>bar</b>"
The problem is that is escapes HTML. How can I replace the content with the HTML string here?
you can always use the module from npm
var unescape = require('unescape');
console.log(unescape(parser.toString()))
When I tested your code there is a small typo: (toReplacce instead of toReplace)
var dom = require('xmldom');
var xml = "<foo><toReplace/></foo>";
var parser = new dom.DOMParser().parseFromString(xml, "text/xml");
var a = parser.getElementsByTagName("toReplace")[0];
//console.dir(a);
a.textvalue = "<b>bar</b>";
console.log(parser.toString());
I have a value that looks like "mailto:a#b.com, mailto:a#b.com'. This is basically a hyperlink field and I want to parse this properly using SharePoint JSOM. I tried SP.FieldUrlValue, but it does not seem to have a method that lets you parse.
You can use the .get_url() function on the actual item value to get the hyperlink URL, or the .get_description() function to get the hyperlink's display text.
var linkField = "internalColumnName";
var listName = "List Title";
var clientContext = new SP.ClientContext();
var list = clientContext.get_web().get_lists().getByTitle(listName);
var camlQuery = new SP.CamlQuery();
var items = list.getItems(camlQuery);
clientContext.load(items);
clientContext.executeQueryAsync(Function.createDelegate(this,function(){
var itemEnumerator = items.getEnumerator();
while(itemEnumerator.moveNext()){
var item = itemEnumerator.get_current();
var url = item.get_item(linkField).get_url(); // <-- Get URL
var text = item.get_item(linkField).get_description(); // <-- Get Text
alert(url + ", " + text);
}
}),Function.createDelegate(this,function(sender, args){alert(args.get_message());}));
I have a notes form with a rich text field on it, called "Body". I've set the "Storage" property of the field to "Store contents as HTML and MIME".
Now, I am creating a new document with that form in the Notes Client.
However, if I try to access the rich text field's value in SSJS with NotesRichTextItem.getMIMEEntity(), it always returns null.
Am I missing something?
Thank you for your help in advance.
Update 2: 02/12/2015
I did some more testing and I found the cause, why it won't recognize the rich text field as MIME Type, but rather always returns it as RICH TEXT:
The cause is me accessing the database with "sessionAsSigner" rather than just using "database".
If I remove "sessionAsSigner" and use "database" instead, making the XPage unavailable to public access users, so, I am forced to log in, the code recognizes it as MIME Type and I can get a handle on NotesMIMEEntity.
Unfortunately, the XPage has to be available to public access users and I have to use sessionAsSigner.
When I open the document properties and I look at the rich text field, I can see that the "Field Flags" are "SIGN SEAL". My guess is, that's why sessionAsSigner doesn't work, but it is just a guess.
Any ideas?
Update 1: 02/12/2015
Here is the code I am using in my SSJS:
var oDBCurrent:NotesDatabase = sessionAsSigner.getDatabase(session.getServerName(), session.getCurrentDatabase().getFilePath());
var oVWMailProfiles:NotesView = oDBCurrent.getView('$vwSYSLookupEmailProfiles');
var oVWPWResetRecipient:NotesView = oDBCurrent.getView('$vwPWPMLookupPWResetNotificationProfiles');
var oDocPWResetRecipient:NotesDocument = null;
var oDocMailProfile:NotesDocument = null;
var oDocMail:NotesDocument = null;
var sServer = session.getServerName();
oDocPWResetRecipient = oVWPWResetRecipient.getDocumentByKey(sServer, true);
oDocMailProfile = oVWMailProfiles.getDocumentByKey('.MailTemplate', true);
oDocMail = oDBCurrent.createDocument();
//Set default fields
oDocMail.replaceItemValue('Form', 'Memo');
oDocMail.replaceItemValue('Subject', oDocMailProfile.getItemValueString('iTxtSubject'));
oDocMail.replaceItemValue('SendTo', oDocPWResetRecipient.getItemValue('iNmesRecipients'))
//Get body text
var oItem:NotesItem = oDocMailProfile.getFirstItem("Body");
var entity:NotesMIMEEntity = oItem.getMIMEEntity();
//Create email body
var tmp = entity.getContentAsText();
//Replace <part2> with part 2 of the password
tmp = #ReplaceSubstring(tmp, "<part2>", sPWPart2);
//Set content of Body field as MIME type
var body = oDocMail.createMIMEEntity();
var stream = session.createStream();
stream.writeText(tmp);
body.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);
//Send email
oDocMail.send();
As I mentioned before, I've also tried:
var oDBCurrent:NotesDatabase = sessionAsSigner.getDatabase(session.getServerName(), session.getCurrentDatabase().getFilePath());
var oVWMailProfiles:NotesView = oDBCurrent.getView('$vwSYSLookupEmailProfiles');
var oVWPWResetRecipient:NotesView = oDBCurrent.getView('$vwPWPMLookupPWResetNotificationProfiles');
var oDocPWResetRecipient:NotesDocument = null;
var oDocMailProfile:NotesDocument = null;
var oDocMail:NotesDocument = null;
var sServer = session.getServerName();
oDocPWResetRecipient = oVWPWResetRecipient.getDocumentByKey(sServer, true);
oDocMailProfile = oVWMailProfiles.getDocumentByKey('.MailTemplate', true);
oDocMail = oDBCurrent.createDocument();
//Set default fields
oDocMail.replaceItemValue('Form', 'Memo');
oDocMail.replaceItemValue('Subject', oDocMailProfile.getItemValueString('iTxtSubject'));
oDocMail.replaceItemValue('SendTo', oDocPWResetRecipient.getItemValue('iNmesRecipients'))
//Get body text
var entity:NotesMIMEEntity = oDocMailProfile.getMIMEEntity('Body');
//Create email body
var tmp = entity.getContentAsText();
//Replace <part2> with part 2 of the password
tmp = #ReplaceSubstring(tmp, "<part2>", sPWPart2);
//Set content of Body field as MIME type
var body = oDocMail.createMIMEEntity();
var stream = session.createStream();
stream.writeText(tmp);
body.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);
//Send email
oDocMail.send();
Try calling sessionAsSigner.setConvertMime(false)
You get the MIMEEntity from the document, not from the Richtext item. See an example here (starting at line 103): https://github.com/zeromancer1972/OSnippets/blob/master/CustomControls/ccSnippets.xsp
You should set the session to not convert MIME to RichText.
Add this at the start of your code.
session.setConvertMime(false);