Updating single items is list using SPservices - sharepoint

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>

Related

How to clear a SharePoint Lookup field with PNP-JS from SPFx WebPart

I have an optional (not-required) Lookup column (Response) in my SharePoint List (Feedback). I am trying to use pnp js to reset the field to nothing.
const response = await this.list.items.getById(change.object.id).update({ResponseId: 0});
Looks like it works in the webview sharepoint. When getting the items, it returns a "bad" lookup with ID=0 and all other fields undefined. Same if I try using -1.
If the field is actually empty, it doesn't return the field at all. How can achieve the same using pnp? E.g. to clear the look up.
Any helps is much appreciated,
Dennis
#Dennis Kuhn,
Can you please set it null like below?
const i = await list.items.getById(3).update({
Title: "My New Title",
ResponseId: null
});
It works well on my SPO list, Could you please have a try?
BR

NetSuite SuiteScript 2.0 How to specify field, sublist field or subrecord field in N/search create API

I have a button on the Purchase Order record that performs a saved search query on the current record and then uses the http module to send that data via a POST to a url. That url then sends the data posted back as part of the success confirmation. The idea with the saved search is to create a javascript object that contains all the data that I want from the purchase order (main record and items sublist with subrecords) and then to use JSON.stringify to create a JSON payload for the http POST. I can't do this with the currentRecord because if you inspect it it only contains the internal id. This would also prevent me from having to go to the great lengths of writing a lot of code to manually build up a JSON string from the currentRecord.
Unfortunately I don't really understand how to specify the column names in the dynamically created saved search. Sometimes it looks to me like the column names are those from the NetSuite Records Browser and other times the script gives an error (column not found) if I use a column name from the NetSuite Records Browser (for example currencysymbol).
I'm also not sure how to specify columns that appear in sublists or subrecords in sublists. I tried to use item.itemtype but this gave me a column not found error. Just item completes successfully but I'm not sure whether this was really successfull since it is difficult to decode the returned result after the JSON.stringify (it adds a lot of backslashes). Using console.log (for some reason I don't get anything back using the NetSuite log.audit) is also quite difficult, although it looks like it is returning an array with 5 rows. So using item might sort of be successful. I say sort of because I have 3 item lines and it is returning 5 array rows.
So basically I would like to know where one can find the names of the columns to use in NetSuite for a saved search; and also how to specify sublist column names and sublist subrecord column names in a saved search.
/**
* #NApiVersion 2.0
* #NScriptType ClientScript
* #NModuleScope SameAccount
*/
define(['N/ui/dialog', 'N/currentRecord', 'N/record', 'N/url', 'N/http', 'N/search'], function (dialog, rec, record, url, http, s) {
function pageInit(context) {
// All client scripts need at least one dummy function.
} // pageInit
function onButtonClick() {
var currentRecord = rec.get();
// Create a saved search dynamically.
var rs = s.create({
type: s.Type.PURCHASE_ORDER,
filters: [
["mainline", s.Operator.IS, "F"], "and",
["internalid", s.Operator.IS, currentRecord.id]
],
columns: [
"internalid",
"currency",
{
name: "item",
sort: s.Sort.ASC // DESC
}
]
});
var myPostDataObj = rs.run().getRange(0, 1000);
console.log(myPostDataObj);
var headers = {
'Content-Type': 'application/json; charset=utf-8',
};
http.post.promise({
url: 'http://httpbin.org:80/post',
body: JSON.stringify(myPostDataObj),
headers: headers
})
.then(function(response){
console.log('SUCCESS: ' + JSON.stringify(response));
})
.catch(function onRejected(reason) {
console.log('ERROR: ' + JSON.stringify(reason));
})
}
return {
pageInit: pageInit,
onButtonClick: onButtonClick
};
}); // Define
There are two Chrome extensions I suggest you get;
NetSuite Field Explorer. This extension will show you the ids (and values) of all the fields in a NetSuite record.
NetSuite Search Export. This extension will convert/export a saved search to SuiteScript.
For what you're doing, I would create your saved search in the UI, and then export it using the Saved Search Export extension, paste that into your code (where s.create is), and work from there.
The first extension is nice to get to the sublist field ids. Saves a lookup in the record browser.

Algolia Instantsearch with Multiple Indices and Multiple Pagination Widgets

I have implemented instantsearch.js with 1 search input and multiple indices, and multiple stats/pagination widgets. Everything seems to be working correctly except for the pagination widgets.
Here is a codepen https://codepen.io/flrrrhoffpauir/pen/EEpWre
collections.addWidget(
instantsearch.widgets.pagination({
container: '#collections-search-pagination',
showFirstLast: false,
labels: {
next: '>',
previous: '<',
},
cssClasses: {
root: 'search-pagination'
}
})
}
search.addWidget(
instantsearch.widgets.pagination({
container: '#stories-search-pagination',
showFirstLast: false,
labels: {
next: '>',
previous: '<',
},
cssClasses: {
root: 'search-pagination'
}
})
}
If you search for ‘martin’ and then click the Stories tab, you can see the results and that the pagination is working. If you now click the Collections tab, you can see that the pagination widget has the correct number of pages based on how many results were returned according to the stats widget, but then you click to go to page 2, you are just scrolled to the top of the page and it doesn’t load the page 2 data.
How can I get two or more pagination widgets on the page at once that both work correctly?
This is what I went off of to create the multiple index search, but they don't cover multiple pagination widgets: https://jsfiddle.net/j9nwpz34/49/
The searchFunction implementation should transfer all the information that needs to be synchronized. For example, in your case you have a pagination widget that you want to sync across instances of InstantSearch, so you want to transfer the pagination property on top of the query parameter.
var search = instantsearch(
{
/* appId: '',
apiKey: '',
indexName: 'movies',*/
searchFunction: function(helper) {
var query = movies.helper.state.query;
var page = movies.helper.state.page;
products.helper.setQuery(query);
products.helper.setPage(page)
products.helper.search();
helper.search();
},
searchParameters: {
hitsPerPage: 3
}
});
I've modified the JSFiddle to match your need. You can learn more about this state by going to the JS Helper documentation (internal state management of InstantSearch.js).
Update based on the jsFiddle provided:
The rest of the example still holds. However, one thing to note is that if you make a modification in the helper, it will reset the page. In the provided fiddle, you do such a change in the collections searchFunction. You will always set the query, which will always reset the page to 0. Hence the bug.
Here is a fixed fiddle

Using SPServices to update SharePoint List

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.

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