How do i get the User Image from a lookup list on Sharepoint 2013? - json

I'm really stuck with getting the User image from a lookup list using AJAX with SharePoint 2013.
Ok so im getting my data from a Sp list called 'Comments', and im selecting a SP generated field called 'Created By' however on my SP its actually called 'Author'. This field only shows an ID so ive expanded it with OData to get the 'Author' details.
So what im trying to do is set up a custom comment section. So im taking data from the 'Author / Created By' column and outputting that on top of the persons comment. This all works fine!
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/DigiBlog/_api/web/lists/getbyTitle('Comments')/items?$select=Comment,Likes,BlogId,Created,Author/ID,Author/FirstName,Author/LastName,Author/Title&$expand=Author/Id",
type: "GET",
headers: {
'accept': 'application/json;odata=verbose'
},
success: function (data) {
for (var i = 0; i < data.d.results.length; i++) {
var item = data.d.results[i];
self.blogComments.push(item);
//item.FirstName = item.FirstName.toLowerCase();
//console.log(item);
}
console.log("Comment User Info Called");
},
error: function () {
console.log("Comment User Info Error");
}
});
What i want is the picture Url from that user, so i can output an image of that person next to each comment. My Sharepoint is part of big organisation so theres a tonne of restrictions in place, one of which means i can't view the list of users so i can't see what fields i can actually use. Ive seen people use 'Picture' value in the select field, however when i try that the Ajax fails.
url: _spPageContextInfo.webAbsoluteUrl + "/DigiBlog/_api/web/lists/getbyTitle('Comments')/items?$select=Comment,Likes,BlogId,Created,Author/ID,Author/FirstName,Author/LastName,Author/Title&$expand=Author/Id",
All im looking for is the Author Img URl, ive tried Author/[Picture, PictureUrl, PictureUri, Image, ImageUri... and so on]. Ive spent 2 days on this and im not getting anywhere fast!
I either want a way to get the Picture Url or a way to show all the avaiable fields of 'Author' using console so i can find the relevant field i need to select.
Can anyone help? Thanks in advance!

It seems that we could not get picture url directly.
Firstly,you could get user name.
/_api/web/lists/getbytitle('Comments')/items(1)?$select=Owner/Name&$expand=Owner
Secondly,you could use this rest api to get picture url.
/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=#v)?#v='domain\username'&$select=PictureUrl
The different versions of rest api versions are introduced here.
Tip:The username obtained in the first step may need to be processed as in the example.

Related

Cannot convert undefined or null to object - DynamoDB

Been testing some Lambda functions and finally managed to get the data to push to DyanmoDB, or at least in the logs it shows the billed duration and this only occurs after I've pushed data to the table, doesn't happen before I test the function.
Basically, I'm just testing a small function to push a UserID and Name to a DynamoDB table. I populate the params as seen below.
var UserID = toAdd['UserID']; var Name = toAdd['Name'];
var params = { Item: { 'UserID':UserID, 'Name':Name }, TableName: 'bookings2D' };
When I console log my params I'm seeing this:
dynamo.putItem(params, dynamoResultCallback);
And as you can see below, the request is at the very least being triggered.
However, when I navigate to my DB Table, and perform a table scan I receive this error:
This only occurs AFTER I run the Lambda function, if I delete and recreate the table this no longer appears. Seems like it's just something small format wise I may not be grasping.
Any help is much appreciated, any questions feel free to ask :)
Thanks
Hard refresh your browser page using CTRL + F5 or CTRL + Shift + R.
I had the same issue while creating table for phone (table name).
As a solution, I recreated the table with a different name (phone_detail).
AND IT WORKED!
You can also try to create table after a while.

Do not change the router values ​in the address

I have a page (index) with an #ActionLink that opens another page to edit an invoice, the page will appear correctly, but the [Url-address] shows the number for the invoice, and when I change the number for the invoice in the [Url-address], it means that he opened another invoice, and I want the modification page not to open from By modifying the [Url-address] or using a direct link, I found a nice way, but it is used with [Post] and not Get. Is there a way to protect the [Url-address] of the page from being modified and its values?
View Index:
#Html.ActionLink(
linkText: "Edit_Invoice",
actionName: "Invoice_Edit",
controllerName: "Invoice",
routeValues: new { ID_Invoice = 2 },
htmlAttributes: new { area = "Pro"})
Controller :
[HttpGet]
public ActionResult Invoice_Edit(int id_invoice)
{
Table.Invoice invoice = (from i in Cn.Invoice
where i.ID_Invoice == id_invoice
select i).FirstOrDefault();
return View(invoice;
}
View Invoice_Edit:
#Html.TextBoxFor(m => m.ID_Invoice)
#Html.TextBoxFor(m => m.Date_Invoice)
<button>save</button>
When you open the invoice modification page, its number will appear in the address as in the link below
https://localhost:44320/Pro/Invoice/Invoice_Edit?ID_Invoice=2
I only want to open invoices that are selected from the page only.
Update 1 : Change Title Answer
if you what users to open only invoices that they are allowed to open, antiforgery token has nothing to do with it. You neeed server side validation, authentication and authorization. All of these should be implemented on the server side. Client side javascript code is not enough.
Anti-Forgery Tokens don't make a lot of sense for any request where you're not modifying and persisting data. So I recommend to remove [ValidateAntiForgeryToken] from your GET since GET request will be returned to the user, not the attacker.
AntiForgeryToken is designed for POST requests and it expects the token in Request.Form collection. You can just use post instead of get to receive data. Or you can use ajax. Google and you will find some examples.
But make sure that you are using them when you're creating, updating or deleting data.

How can I build a website with fields that any visitor can edit?

I'd like to build a website which has the following features:
There should be a few fields which store numerical values.
These fields should be editable by anyone who visits the site
A second order feature which would be nice, but isn't necessary
It would be nice if when multiple people are visiting the site and one visitor updates a value, the webpage reloads for all visitors once the value is saved, updating the value seen for all users
How would I go about implementing the above?
I'm not sure what terms I should even be googling to approach this question, so any advice is appreciated.
To your first question:
const editMe = document.getElementById('edit-me');
editMe.addEventListener('input', () => {
const editedToInt = Number(editMe.innerHTML);
if (!Number.isInteger(editedToInt)) {
// Value is invalid
editMe.style.border = "2px solid red";
}
else {
// Value is valid. Do something with it...
editMe.style.border = "inherit";
}
})
<div id="edit-me" contenteditable>100</div>
The user can edit the content and only numbers are allowed.
To your second question:
You could save the value which the user has typed in your database. Also you need to use Ajax to check the value in your database every 5 seconds. If the value in your database is different than the value in the DOM, you will replace it.

Minimizing server trips in setting default value in 1:n relationship in lightswitch html5 client

I have lightswitch entities created in the HTML5 client. There is a field that the user should not be setting that needs to be set based on their login. In this case, the client the user is associated with.
The standard examples (in Michael Washington's book Creating HTML 5 Websites ... Using Lightswitch and all over the web) involve assigning the user name as the relevant field, setting up a little handler on the server to return the relevant field using an AJAX call.
This is was all well and good while prototyping, but now that we are doing this for real, there is a relationship to another entity involved, the Client Entity, so you can't just assign the Client Id. So instead of simply assigning a Client ID, now we have associate a whole Client Object to the entity.
Here the suggestion is to do what ends up looking like this:
myapp.activeDataWorkspace.ApplicationData.Clients_SingleOrDefault(1).execute().then(function (ClientQuery) {
entity.setClient(ClientQuery.results[0]);
});
My problem is with this part:
Clients_SingleOrDefault(1)
I need to get that number dynamically, not just a hard coded 1, as that OP suggested. So I can do it in two server calls, one to get the ID, and then the next one to substitute that result into the next call, but that seems ... inefficient.
msls.promiseOperation(CallGetClientId).then(function PromiseSuccess(PromiseResult) {
myapp.activeDataWorkspace.ApplicationData.Clients_SingleOrDefault(Number(PromiseResult)).execute().then(function (ClientQuery) {
entity.setClient(ClientQuery.results[0]);
});
});
function CallGetClientId(operation) {
$.ajax({
type: 'post',
data: {},
url: '../UserCode/GetClientId.ashx',
success: operation.code(function AjaxSuccess(AjaxResult) {
operation.complete(AjaxResult);
})
});
}
It would seem that there should be a better way to do it. Is there?
The simplest method of achieving this with one server call is to implement a scalar query.
For example, if you create a scalar query called ClientForCurrentUser against your Clients table you'd be able to make a single client side call as follows:
myapp.activeDataWorkspace.ApplicationData.ClientForCurrentUser().execute().then(function (query) {
if (query && query.results && query.results.length !== 0) {
entity.setClient(query.results[0]);
}
});
As regards configuring the scalar query, the following post covers an example (note the setting of the 'Number of Results Returned' property):
Applying where clause to child collection in LightSwitch query
Then, assuming you have a field against your Client record that relates it to the current username (e.g. Client.RelatedUser) you'd implement the following type of PreprocessQuery method against the scalar query:
partial void ClientForCurrentUserPersonForCurrentUser_PreprocessQuery(ref IQueryable<Client> query)
{
var username = this.Application.User.Name;
query = query.Where(c => c.RelatedUser.Equals(username, StringComparison.OrdinalIgnoreCase)).Take(1);
}

Displaying date from mysql in a Jquery Mobile dropdown

I started making an app with use of Jquery mobile(JQM) to be used for a customer database. You should be able to create a customer name, address etc. The information will then be stored in a MySQL database. The part I've got under control.
Now I want to do so that it is possible to retrieve customer number and name of the database again and show them in a drop down menu from JQM.
So something like:
"SELECT
kundenummer, navn
FROM
kundeskema
ORDER BY
id
DESC";
I have my database connection and my php page, but how do I get the information from where I make my sql statement and to my html page? Know it is using AJAX but dont understand how to do. I know it's a fairly simple task, but it's not for me.
plz help
Morten
You can create a PHP file which returns a JSON string of your data. Then do a jQuery ajax call to this PHP file and in the success callback create elements and add them the select element.
e.g.:
$.ajax({
url: myValues.php,
success: function(data) {
template = //create option elements
$('#mySelect').html(template);
}
});
Or
https://github.com/tkompare/projects/tree/master/ajaxexample
This is for a listview but the idea is the same