Convert Date field while retreiving from Sharepoint list in client object - com

I am creating a windows forms which loads list items from sharepoint client object model.
I am having issue with Date field which is giving +1 day or -1 day i.e if i have entered date as 5/5/2014 it gives 5/6/2014 or sometimes 5/4/2014.
_query.ViewXml = "<View><Query><Where>" +
"<And><Geq><FieldRef Name='Effort_x0020_Date'/><Value IncludeTimeValue='FALSE' Type='DateTime'>" + conStartDate + "</Value></Geq>" +
"<And><Leq><FieldRef Name='Effort_x0020_Date'/><Value IncludeTimeValue='FALSE' Type='DateTime'>" + conEndDate + "</Value></Leq>" +
"<Eq><FieldRef Name='Author' LookupId=’TRUE’/><Value Type=’Text’>" + UserID + "</Value></Eq></And></And></Where>" +
"<GroupBy Collapse='TRUE'><FieldRef Name='WBS_x0020_Code'/></GroupBy></Query><RowLimit>25</RowLimit></View>";
SP.ListItemCollection _listitems = list.GetItems(_query);
clientcontext.ExecuteQuery();
After executing this if i use the below code it works properly but takes lot of time.
foreach(ListItem item in _listitems) {
DateTime start = ((DateTime) item["Effort_x0020_Date"]);
ClientResult < string > result = Utility.FormatDateTime(clientcontext, clientcontext.Web, start, DateTimeFormat.DateTime);
clientcontext.ExecuteQuery();
DateTime rightStart = Convert.ToDateTime(result.Value, new CultureInfo((int) web.Language));
//item["Effort_x0020_Date"] = rightStart;
}
Somehow i want an alternate way by which this could be done faster so that everytime connecting to sharepoint is avoided.

I resolved the issue by putting
_query.DatesInUtc=false.
It worked!!

Related

Google cloud Endpoint REST API - call with multiples arguments

I have to make a small project for school, and I have to create and use an API Rest with google endpoint.
I have created my method:
image corresponds to the string obtained with the method new FileReader().readAsDataURL used in my frent-end on an image.
user corresponds to a google account (using the credential).
#ApiMethod(name = "createNewPost", httpMethod = HttpMethod.GET)
public void createNewPost(#Named("image") String image, User user) throws
UnauthorizedException, EntityNotFoundException {
if (user == null) {
throw new UnauthorizedException("Invalid credentials");
}
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Calendar date = Calendar.getInstance();
//Creates the post with relevant data
Entity tinyPost = new Entity("Post");
tinyPost.setUnindexedProperty("User", user.getId());
tinyPost.setUnindexedProperty("Image", image);
datastore.put(tinyPost);
//Creates the post index containing all receiver and linked with the post
Entity tinyPostIndex = new Entity("PostIndex", (3000 - date.get(Calendar.YEAR)) + ":" +
(12 - date.get(Calendar.MONTH)) + ":" +
(31 - date.get(Calendar.DAY_OF_MONTH))+ ":" +
(24 - date.get(Calendar.HOUR_OF_DAY))+ ":" +
(60 - date.get(Calendar.MINUTE))+ ":" +
(60 - date.get(Calendar.SECOND)));
tinyPostIndex.setUnindexedProperty("Post", tinyPost.getKey());
tinyPostIndex.setProperty("Receiver", datastore.get(KeyFactory.stringToKey(user.getId())).getProperty("Subscribers"));
datastore.put(tinyPostIndex);
}
So I use the url to make my request:
"_ah/api/myApi/v1/createNewPost" + '?image=' + reader.result + '&access_token=' + Login.ID
The problem is that I get a 400 error every time.
I tried replacing reader.result with a regular string, but it doesn't change anything.
I have another method with only User as parameter and it works fine
"_ah/api/myApi/v1/registerUser" + '?access_token=' + Login.ID
Thanks

When, why and how to avoid KeyError in Odoo Development

I´ve noticed that some custom modules that I develop can be installed on databases with records, while others throw the KeyError message, unless the database is empty (no records). Generally the errors appear when the module contains computed fields. So, does anybody know why this happens? and how my code should look like to avoid this kind of errors?
an example computed field that throws this errors looks like this:
from odoo import models, fields, api
from num2words import num2words
Class InheritingAccountMove(models.Model):
_inherit = 'account.move'
total_amount_text = fields.Char(string='Total', compute='_compute_total_amount_text', store=True)
#api.depends('amount_total')
def _compute_total_amount_text(self):
lang_code = self.env.context.get('lang') or self.env.user.lang
language = self.env['res.lang'].search([('iso_code', '=', lang_code)])
separator = language.read()[0]['decimal_point']
for record in self:
decimal_separator = separator
user_language = lang_code[:2]
amount = record.amount_total
amount_list = str(amount).split(decimal_separator)
amount_first_part = num2words(int(amount_list[0]), lang=user_language).title() + ' '
amount_second_part = amount_list[1]
if len(amount_second_part) == 0:
amount_text = amount_first_part + '00/100'
elif len(amount_second_part) < 2:
amount_text = amount_first_part + amount_second_part + '0/100'
else:
amount_text = amount_first_part + amount_second_part[:2] + '/100'
record.total_amount_text = amount_text
UPDATED
The reason your code has a problem in this situation is that when there are no records in the table(at time of installation) your loop won’t run which result in no value assigning of your computed field so
Add the first line of code in function
self.total_amount_text = False This is required to assign value to the computed field in compute function from Odoo 13 and maybe 12
----------------------------------------------------------------
Other reasons could be :
This error occurs when one tries to access a key from a dictionary that doesn't exist like,
language.read()[0]['decimal_point']
the dictionary may not have 'decimal_point' at the time of installation of the module, which may have returned this error a common way to handle this is by checking if the key exists or not before accessing it like,
if 'decimal_point' in language.read()[0].keys()
also, a dictionary can also be empty in that case the language.read()[0] will throw an error
I´ve changed my code making it specifically for spanish and the error doesn´t appear anymore. I appreciate Muhammad´s answer, maybe he´s right but anyway here is the modified code:
#api.depends('invoice_line_ids')
def _compute_total_amount_text(self):
for record in self:
amount = record.amount_total
amount_list = str(amount).split('.')
amount_first_part = num2words(int(amount_list[0]), lang='es').title() + ' '
amount_second_part = amount_list[1]
if len(amount_second_part) == 0:
amount_text = amount_first_part + '00/100'
elif len(amount_second_part) < 2:
amount_text = amount_first_part + amount_second_part + '0/100'
else:
amount_text = amount_first_part + amount_second_part[:2] + '/100'
record.total_amount_text = amount_text

Docusign - Embedded Signing with multiple recipients in single document - ASP.Net Core

I'm trying to implement docusign with embedded signing approach in ASP.Net Core using DocuSign.eSign.dll (3.0.1). I have been able to do it with single recipient but now I want that document to be signed by multiple recipients. Does anyone has working example who can share?
Thank you in advance!
I do have an example for you, but using node.JS and not C#, it's the same thing, just translate it to your lang. You can actually either see the live code here -https://loancosample.esigndemos.com and select the right most option (sailboat loan).
The source code is here - https://github.com/docusign/sample-app-loanco-nodejs. The specific one you looking for is here - https://github.com/docusign/sample-app-loanco-nodejs/blob/master/routes/loan-sailboat.js and I can copy/paste here the relevant code:
// Recipients
var signer = new docusign.Signer();
signer.routingOrder = 1;
signer.email = body.inputEmail;
signer.name = body.inputFirstName + ' ' + body.inputLastName;
signer.recipientId = '1';
signer.excludedDocuments = ['3'];
if(body.inputSigningLocation == 'embedded'){
signer.clientUserId = '1001';
}
if(body.inputAccessCode && body.inputAccessCode.length){
signer.accessCode = body.inputAccessCode;
}
if(body.inputAuthentication == 'phone'){
app.helpers.addPhoneAuthToRecipient(signer, body.inputPhone);
}
var appraiserSigner = new docusign.Signer();
appraiserSigner.routingOrder = 2;
appraiserSigner.email = body.inputAppraiserEmail;
appraiserSigner.name = body.inputAppraiserFirstName + ' ' + body.inputAppraiserLastName;
appraiserSigner.recipientId = '2';

How to add line break to labels on axis for IE9?

I'm using Dojo 1.9.1.
I'm using dojox.charting to draw some charts.
I am using a labelFunc to produce a date/time label for my X-axis. This is working fine in all browsers.
But I want to add a line break to my label so that the date sits above the time, e.g.:
10/01/2014
06:00
I can add a html break tag to the string returned and this works in Chrome and Firefox but not IE9 (to be expected).
Has anybody solved how to do this one that works across all browsers including IE9 (or specifically ones that don't "do" html labels).
Cheers
Ian
My label func:
_labelFull: function (index) {
// Returns a label in the form "dd/mm/yyyy hh:mm" for tooltip labelling
var dt,
d;
dt = new Date(Date.parse(myglobalStartDateTime));
dt.setHours(dt.getHours() + Number(index));
// Full date/time
d = ("0" + dt.getDate()).slice(-2) + '/' +
("0" + (dt.getMonth() + 1)).slice(-2) + '/' +
dt.getFullYear() + ' ' +
("0" + dt.getHours()).slice(-2) + ':' +
("0" + dt.getMinutes()).slice(-2) + 'UTC';
return d;
}

Save Image-Path into SQL, Webmatrix

I want to create a group-function to my Website. In every group there should be a group-image, which people can upload. So I must save the path into my SQL-DB. My Code:
newFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(photo.FileName);
imagePath = #"images\" + newFileName;
imageThumbPath = #"images\thumbs\" + newFileName;
var setPath = (#"~\" + imageThumbPath);
var intoGroupImg = ("UPDATE groups SET img= " + #setPath+ " WHERE id= "+#grID);
db.Execute(intoGroupImg);
I always get the error-message: Token line number = 1,Token line offset = 26,Token in error = images. I don't know why.
I've got a solution:
var intoGroupImg = ("UPDATE groups SET img = #0 WHERE id= " +#grID);
db.Execute(intoGroupImg, imageThumbPath);
First off, please, please use parameterized queries. It is your smoking gun versus SQL injection. Even if you're not adding user-input, it is a good habit to get into.
Anyway, I'm not sure what some of your # symbols are in there for, but I am used to using C#.net with WebMatrix, but I think that is what you're using also. Try this:
var newFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(photo.FileName);
var imagePath = "images/" + newFileName;
var imageThumbPath = "images/thumbs/" + newFileName;
var setPath = "~/" + imageThumbPath;
var intoGroupImg = "UPDATE groups SET img = #0 WHERE id = #1";
db.Execute(intoGroupImg, setPath, grID);
This is how I would imagine it to look in C# with parameterized queries.
Given the line offset I believe the error is from #setPath but I'm not sure. Try going to the database tab in WebMatrix and manually doing a query with what you expect the value of #setPath to be.
Also, I noticed you used "backslashes" instead of "forward slashes" in the concatenated string in your example. Is this intentional? Is that what the # symbol is doing? Keeping you from having to escape each backslash with \\? Either way, the forward slash / in its place should do fine, no?
Anyway, hope I helped, at least some.