Using SPServices to update SharePoint List - sharepoint

I want to change a property of a SharePoint list item with given input. I used the documentation and got this, but I'm not sure what I'm doing wrong. There could be something completely wrong because I'm not too experienced.
$().SPServices(
{
operation: "UpdateListItems",
async: false,
listName: "TechInv",
Number: itemNumber,
valuepairs: [[property, replacement]],
completefunc: function(xData, Status) {
// ...
}
});

The SPServices plugin is well documented. In your case, it seems that you are missing the item ID.

You can use Firebug (addon of Firefox) or the web toolbar of your browser to look at the query that is sent to the server, as well as the error message returns by the server. That way you can more easily find where the issue is.
In your case you used "Number" instead of "ID" I think.
BTW, I created a Sharepoint API in JavaScript that is, I think, easier to use than SPServices. It's there : SharepointPlus

$().SPServices(
{
operation: "UpdateListItems",
async: false,
listName: "TechInv",
ID: itemNumber,
valuepairs: [[property, replacement]],
completefunc: function(xData, Status) {
// ...
}
});
ID is the change and it should work.

Related

CloudantDB: using db.get without id

I have a table:
id: 001
name: test
provider_id:ABC123
and I try to query with provider_id and get a error message, but not with id:001
db.get("ABC123", function(err, data) {
// The rest of your code goes here. For example:
console.log("Found id:", data);
});
Please give me your thoughts how to run successfully db.get + provider_id
You can't use db.get without the ID. However you can use either Query or Views to find the document you are looking for.
With query you can use a selector such as {"provider_id":"ABC123"} to find the documents which contain that provider id.
With views you can use the provider_id as the key and the doc id or null as the value, such as:
function (doc) {
emit(doc.provider_id, doc._id);
}
If you are using null as the value, you should use the include_docs=true option for the request. See your library's documentation on how to use views and query.

How to autogenerate id if there is no id in document with elasticjs v5.0

I am trying to add documents, according to elastic search documents, we can add document, even if we dont provide id... See Here
I am trying to add a document even if it doesnt have any ID. in elastic search, how can i do that?
My current code looks like this
var params = _.defaults({}, {
index: index,
type: type, //'customer'
id: data.id || null,
body: data
})
debug(params)
return this.client.create(params);
The above code gives this error
{
"error": "Unable to build a path with those params. Supply at least index, type, id"
}
Any hint would help, thanks
With the create call you MUST provide an id.
If you are not sure if an ID will be present in your data , then you can use the client.index() function instead. using that function, ES will auto-generate an ID if none is provided.

Inserting a user into a person field in sharepoint using the rest api

I'm trying to update a list item in a remote sharepoint site using the rest api from a workflow. I'm having issues understanding how to populate a person field. I've looked online and read that you should use the id of the user and not the login, however what if I do not know the users id? Where can I get this from?
I've been reading the following link but it doesn't explain where the id comes from
how to add user to sharepoint list item user field using REST api in sp2013?
You will be able to view all UserProfile Properties by using this REST call:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=#v)?#v='domain\user'
To get a specific Property (in this case UserProfileGUID) use:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=#v,propertyName='UserProfile_GUID')?#v='domain\user'
If you are using CSOM this might help you:
The proper way to write a SharePoint User to a User Field in a SharePoint list
I have done this successfully in the past using both CSOM (js) and SSOM (powershell).
I know its a a bit late but for anyone looking for the answer on how to get the user id use the below function
function getUserId(userName) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/siteusers?$select=Id&$filter=Title eq '" + userName + "'",
type: 'GET',
headers: {
"Accept": "application/json;odata=verbose"
},
success: function (data) {
return data.d.results[0].Id;
},
error: function (error) {
console.log(error);
}
});
}

Updating single items is list using SPservices

I've been struggling to learn how to use SPservices. What I am trying to accomplish is creating a simple input button that will update my item on my list automatically and refresh my page.
Now where I am getting confused here is that the field I am trying to update is an input box (plain text basically). Users would add their dates on that input box manually in this format 03/09/2015 20:48 (MM/DD/YYYY HH:MM). I want to add that button for each item on that row, so that when a user clicks on it, it calculates the current time and adds an extra hour.
I scavenged the web for similar situation as mine but cant seem to get any examples to work with. Just looking for some help, advice, pointers anything at this point.
$().SPServices({
operation: "UpdateListItems",
listName: "List Name",
ID: ID,
valuepairs: valuePairs,
completefunc: function(xData, Status) {
//Callback
}
});
Figured it out, i created a new column and added the item's ID to it and put the row's TD as display: none;. This would essentially hide but with javascript I can still get its information. I then created another column with my button and gave the class update_button and its working great now.
I know this isnt exactly what I said I wanted but this solves a big portion of this puzzle. Hope this helps someone.
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$(".update_button").click(function() {
var id = $(this).closest("tr").find(".hidden_ID").text();
$().SPServices({
operation: "UpdateListItems",
async: false,
batchCmd: "Update",
listName: "Severities",
ID: id,
valuepairs: [["Notes", "Updated"]],
completefunc: function (xData, Status) {
alert(id);
}
});
});
});
</script>

Pulling links to all documents that have a column "XXXX" in sharepoint

I have a site collection in which there are lot of sites, and each site has a number of documents which are tagged as "XXX" in a particular column. Now, if I have to pull links to all documents in the site collection that are tagged "XXX" and display them in a list, how do I go about it? I mean how do I start it?
Do you have any knowledge with JavaScript ? Because you could use it to do this kind of task...
For example with SPServices you can get all the sites:
$().SPServices({
operation: "GetAllSubWebCollection",
completefunc: function(xData, Status) {
$(xData.responseXML).find("Webs > Web").each(function() {
var $node = $(this);
getDocuments( $node.attr("Title") );
});
}
});
Then with SharepointPlus (because the syntax is easier but you can still use SPServices) you can get the documents:
function getDocuments(site) {
$SP().list("My Document List", site).get({fields:"Title",where:"My_x0020_Column = 'XXX'"}, function(data) {
for (var i=data.length; i--;) console.log(data[i].getAttribute("Title"))
})
}
Of course at this point, instead of console.log you should inject the link into your webpage.
It's just a very basic example of what you could do.

Resources