I would like to set the string value to the object id when I create the object below. At the moment it prints "nil". Any ideas? Thanks
var date:NSDate = currentDatePicker.date
var DOB:NSDate = DOBPicker.date
var user = PFUser.currentUser()
var report = PFObject(className:"reports")
report["name"] = nameTextField.text
report["DOB"] = DOB
report["date"] = date
report["user"] = user
report.saveInBackground()
var ojId = report.objectId
println(ojId)
saveInBackground is an asynchronous method, so it doesn't wait. The reason why the id is not set is because the entity has not been saved yet.
I think you should use saveInBackgroundWithBlock: and retrieve the object id form within the block (which is executed after the entity has been saved):
var report = PFObject(className:"reports")
report["name"] = nameTextField.text
report["DOB"] = DOB
report["date"] = date
report["user"] = user
report.saveInBackgroundWithBlock { (success, error) -> Void in
if success {
var ojId = report.objectId
println(ojId)
}
}
or maybe also save, which is performed synchronously - but do not use that from the main thread:
report.save()
var ojId = report.objectId
println(ojId)
Related
I'm trying to update NetSuite Department via WSDL but I'm having an issue updating isInactive. Below is my code in C#:
var record = new com.netsuite.webservices.Department
{
internalId = dp.InternalId,
isInactive = dp.InActive
};
then called
var result = ServiceClient.update(record);
The Department's DEPARTMENT IS INACTIVE on NetSuite doesn't check whether I set it to true or false. What am I doing wrong here?
You forgot to set isInactiveSpecified
Try this:
var record = new com.netsuite.webservices.Department
{
internalId = dp.InternalId,
isInactive = dp.InActive,
isInactiveSpecified = true
};
You need to first .get() the record, set some properties, then .update() the record. Here's what works for me:
var ns = new NetSuite.NetSuiteService();
// passport info skipped
var departmentRef = new RecordRef
{
internalId = "1",
type = RecordType.department,
typeSpecified = true
};
var response = ns.get(departmentRef);
var department = response.record as Department;
department.isInactive = true;
ns.update(department);
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);
I have a page where users can modify their own records in my database. This works well, but i'm trying to tidy up all the security flaws. As you can see from the code below, This page gets data using a querystring parameters. At the moment, anyone can change this query string and edit any record.
How do i incorporate a check using the "RequireAuthenticatedUser" and the matching UserID field in the PropertyInfo table?
Current code:
#{
Layout = "~/_SiteLayout.cshtml";
WebSecurity.RequireAuthenticatedUser();
var db = Database.Open("StayInFlorida");
var rPropertyId = Request.QueryString["PropertyID"];
var Propertyinfo = "SELECT * FROM PropertyInfo WHERE PropertyID=#0";
var qPropertyinfo = db.QuerySingle(Propertyinfo, rPropertyId);
}
Presumably, your PropertyInfo table also holds the property owner's user ID? If so, just include it in the WHERE clause and pass in the CurrentUserId value:
var PropertyInfo = "SELECT * FROM PropertyInfo WHERE PropertyId = #0 AND UserId = #1";
var qPropertyinfo = db.QuerySingle(Propertyinfo, rPropertyId, WebSecurity.CurrentUserId);
In an odata webapi call which returns a PageResult I extract the requestUri from the method parameter, manipulate the filter terms and then construct a new ODataQueryOptions object using the new uri.
(The PageResult methodology is based on this post:
http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options )
Here is the raw inbound uri which includes %24inlinecount=allpages
http://localhost:59459/api/apiOrders/?%24filter=OrderStatusName+eq+'Started'&filterLogic=AND&%24skip=0&%24top=10&%24inlinecount=allpages&_=1376341370337
Everything works fine in terms of the data returned except Request.GetInLineCount returns null.
This 'kills' paging on the client side as the client ui elements don't know the total number of records.
There must be something wrong with how I'm constructing the new ODataQueryOptions object.
Please see my code below. Any help would be appreciated.
I suspect this post may contain some clues https://stackoverflow.com/a/16361875/1433194 but I'm stumped.
public PageResult<OrderVm> Get(ODataQueryOptions<OrderVm> options)
{
var incomingUri = options.Request.RequestUri.AbsoluteUri;
//manipulate the uri here to suit the entity model
//(related to a transformation needed for enumerable type OrderStatusId )
//e.g. the query string may include %24filter=OrderStatusName+eq+'Started'
//I manipulate this to %24filter=OrderStatusId+eq+'Started'
ODataQueryOptions<OrderVm> options2;
var newUri = incomingUri; //pretend it was manipulated as above
//Reconstruct the ODataQueryOptions with the modified Uri
var request = new HttpRequestMessage(HttpMethod.Get, newUri);
//construct a new options object using the new request object
options2 = new ODataQueryOptions<OrderVm>(options.Context, request);
//Extract a queryable from the repository. contents is an IQueryable<Order>
var contents = _unitOfWork.OrderRepository.Get(null, o => o.OrderByDescending(c => c.OrderId), "");
//project it onto the view model to be used in a grid for display purposes
//the following projections etc work fine and do not interfere with GetInlineCount if
//I avoid the step of constructing and using a new options object
var ds = contents.Select(o => new OrderVm
{
OrderId = o.OrderId,
OrderCode = o.OrderCode,
CustomerId = o.CustomerId,
AmountCharged = o.AmountCharged,
CustomerName = o.Customer.FirstName + " " + o.Customer.LastName,
Donation = o.Donation,
OrderDate = o.OrderDate,
OrderStatusId = o.StatusId,
OrderStatusName = ""
});
//note the use of 'options2' here replacing the original 'options'
var settings = new ODataQuerySettings()
{
PageSize = options2.Top != null ? options2.Top.Value : 5
};
//apply the odata transformation
//note the use of 'options2' here replacing the original 'options'
IQueryable results = options2.ApplyTo(ds, settings);
//Update the field containing the string representation of the enum
foreach (OrderVm row in results)
{
row.OrderStatusName = row.OrderStatusId.ToString();
}
//get the total number of records in the result set
//THIS RETURNS NULL WHEN USING the 'options2' object - THIS IS MY PROBLEM
var count = Request.GetInlineCount();
//create the PageResult object
var pr = new PageResult<OrderVm>(
results as IEnumerable<OrderVm>,
Request.GetNextPageLink(),
count
);
return pr;
}
EDIT
So the corrected code should read
//create the PageResult object
var pr = new PageResult<OrderVm>(
results as IEnumerable<OrderVm>,
request.GetNextPageLink(),
request.GetInlineCount();
);
return pr;
EDIT
Avoided the need for a string transformation of the enum in the controller method by applying a Json transformation to the OrderStatusId property (an enum) of the OrderVm class
[JsonConverter(typeof(StringEnumConverter))]
public OrderStatus OrderStatusId { get; set; }
This does away with the foreach loop.
InlineCount would be present only when the client asks for it through the $inlinecount query option.
In your modify uri logic add the query option $inlinecount=allpages if it is not already present.
Also, there is a minor bug in your code. The new ODataQueryOptions you are creating uses a new request where as in the GetInlineCount call, you are using the old Request. They are not the same.
It should be,
var count = request.GetInlineCount(); // use the new request that your created, as that is what you applied the query to.
I have the following xml schema.
<Rooms>
<Room RoomNumber="room1" EMAIL="ssds#dsfd.com" dsfdd=""/>
<Room RoomNumber="room2" EMAIL="ssds#sdd.com" dsfdd=""/>
</Rooms>
I have to return Email address based on the input(input to program is room number).
How i can achieve this using LINQ to XML?
Try this:
var xml = XElement.Parse("<Rooms>"+
"<Room RoomNumber=\"room1\" EMAIL=\"ssds#dsfd.com\" dsfdd=\"\"/>"+
"<Room RoomNumber=\"room2\" EMAIL=\"ssds#sdd.com\" dsfdd=\"\"/>"+
"</Rooms>");
string room = "room1"; //input
var email = xml.Elements("Room")
.Where(c => c.Attribute("RoomNumber").Value == room)
.Select(c => c.Attribute("EMAIL").Value).FirstOrDefault();
var doc = XDocument.Load(myXmlFilePath);
// or doc = XDocument.Parse(myXmlString);
string roomNumber = "room1";
var emailQuery = from room in doc.Root.Elements("Room")
where (string)room.Attribute("RoomNumber") == roomNumber
select (string)room.Attribute("EMAIL");
Then, with a query like that you can get results:
// if there is always only one <Room> with given roomNumber
var email = emailQuery.First();
// otherwise
var emails = emailQuery.ToList();