Pulling links to all documents that have a column "XXXX" in sharepoint - 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.

Related

Hubspot API - list of properties needed (nodejs)

I am integrating the hubspot API to track user interaction with our site. I am creating dynamic lists and I want to filter a user into a certain contact list by which URL they visit.
"filters": [
[
{
"operator": "CONTAINS",
"property": "hs_URL",
"value": `${id}`
},
],
]
I keep getting this error for all my attempts:
{"status":"error","message":"Couldn't find a Property with the given name 'hs_URL'","correlationId":"0723dcee-534b-4f92-9104-509d6885abbe","propertiesErrorCode":"PROPERTY_NOT_FOUND"},
I cannot seem to find a master property list and have tried many string combinations. Anyone familiar with hubspot property lists would be my savior.
Thank you~!
It's been a few months, so you may not need this anymore, but since I landed here while looking for a way to get all the properties from an object type in hubspot using nodejs, this might help others looking for the solution.
The master list of properties can be retrieved with the following API call:
const response = await hubspotClient.crm.properties.coreApi.getAll(objectType, false);
The arguments for getAll() expect:
objectType: a string, i.e "contacts".
archived: a boolean, i.e false. Set this true if you want to get archived properties.
The following code was adapted based on this page from the hubspot API docs:
https://developers.hubspot.com/docs/api/crm/properties
Once you're on the page, you can click on the "Endpoints" Tab to reveal code snippets for multiple environments, including nodejs.
For this example, getProperties(), retrieves all properties for a given object type. I used contacts for the object type, which I believe is where you are storing the url property, but you could use the same function to get properties for other object types such as companies or deals.
It might be worth noting that I mapped the results to return just the property names, which sounds like all you need for your case, but more information is contained in the results if you need it. Just remove this bit to get more information on each property:
.map(prop => prop.name)
const hubspot = require('#hubspot/api-client')
const hubspotClient = new hubspot.Client({ apiKey: "YOUR_API_KEY" })
const getProperties = async (objectType) => {
try {
const response = await hubspotClient.crm.properties.coreApi.getAll(objectType, false);
return response.body.results.map(prop => prop.name);
} catch (e) {
e.message === 'HTTP request failed'
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e);
}
}
Here's an example for running the function to get a list of all property names for contacts.
(async () => {
var properties = await getProperties("contacts");
console.log(JSON.stringify(properties ,null,2));
})();
It took me a bit to find this, so figured I would post here in the hopes it saves time for someone else. This is the first time I've posted a solution, and I'm pretty new to this API and Hubspot in general, so feedback and/or better solutions are welcome. Cheers.

Contentful JS API: Query for related articles with similar tags as the currently viewed article ? (article…tagList[])

Overview:
Someone views an article (contenttype : article). This article has a list of tags (contenttype : articletags).
Based on the linked tags in this article, I am trying to do a query for articles which has one or more of the same tags linked to it (call it Related Articles with same tags).
Here is the structure:
let tags = article.items[0].fields.tagsList.map(tag => {
return tag.fields.navn
})
Which I need to query for articles like this:
contentful.getEntries({content_type: ‘article’}) ???
How can I query for the ids?
I think what you're looking for is the links_to query parameter.
With this one you can figure out which entries relate to another one.
client.getEntries({
links_to_entry: '<entry_id>'
})
You can use the [in] operator to query for entries with a given tag.
contentful
.getEntries({
content_type: "article",
'fields.tags': "website" , //tag id = website
})
.then(({ items }) => {
console.log(items);
})
.catch(console.error);
reference: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/inclusion

Mongoose display comments and stars(likes) for each post [duplicate]

In Mongoose, I can use a query populate to populate additional fields after a query. I can also populate multiple paths, such as
Person.find({})
.populate('books movie', 'title pages director')
.exec()
However, this would generate a lookup on book gathering the fields for title, pages and director - and also a lookup on movie gathering the fields for title, pages and director as well. What I want is to get title and pages from books only, and director from movie. I could do something like this:
Person.find({})
.populate('books', 'title pages')
.populate('movie', 'director')
.exec()
which gives me the expected result and queries.
But is there any way to have the behavior of the second snippet using a similar "single line" syntax like the first snippet? The reason for that, is that I want to programmatically determine the arguments for the populate function and feed it in. I cannot do that for multiple populate calls.
After looking into the sourcecode of mongoose, I solved this with:
var populateQuery = [{path:'books', select:'title pages'}, {path:'movie', select:'director'}];
Person.find({})
.populate(populateQuery)
.execPopulate()
you can also do something like below:
{path:'user',select:['key1','key2']}
You achieve that by simply passing object or array of objects to populate() method.
const query = [
{
path:'books',
select:'title pages'
},
{
path:'movie',
select:'director'
}
];
const result = await Person.find().populate(query).lean();
Consider that lean() method is optional, it just returns raw json rather than mongoose object and makes code execution a little bit faster! Don't forget to make your function (callback) async!
This is how it's done based on the Mongoose JS documentation http://mongoosejs.com/docs/populate.html
Let's say you have a BookCollection schema which contains users and books
In order to perform a query and get all the BookCollections with its related users and books you would do this
models.BookCollection
.find({})
.populate('user')
.populate('books')
.lean()
.exec(function (err, bookcollection) {
if (err) return console.error(err);
try {
mongoose.connection.close();
res.render('viewbookcollection', { content: bookcollection});
} catch (e) {
console.log("errror getting bookcollection"+e);
}
//Your Schema must include path
let createdData =Person.create(dataYouWant)
await createdData.populate([{path:'books', select:'title pages'},{path:'movie', select:'director'}])

Cloud Functions Query Database [duplicate]

Given the data structure below in firebase, i want to run a query to retrieve the blog 'efg'. I don't know the user id at this point.
{Users :
"1234567": {
name: 'Bob',
blogs: {
'abc':{..},
'zyx':{..}
}
},
"7654321": {
name: 'Frank',
blogs: {
'efg':{..},
'hij':{..}
}
}
}
The Firebase API only allows you to filter children one level deep (or with a known path) with its orderByChild and equalTo methods.
So without modifying/expanding your current data structure that just leaves the option to retrieve all data and filter it client-side:
var ref = firebase.database().ref('Users');
ref.once('value', function(snapshot) {
snapshot.forEach(function(userSnapshot) {
var blogs = userSnapshot.val().blogs;
var daBlog = blogs['efg'];
});
});
This is of course highly inefficient and won't scale when you have a non-trivial number of users/blogs.
So the common solution to that is to a so-called index to your tree that maps the key that you are looking for to the path where it resides:
{Blogs:
"abc": "1234567",
"zyx": "1234567",
"efg": "7654321",
"hij": "7654321"
}
Then you can quickly access the blog using:
var ref = firebase.database().ref();
ref.child('Blogs/efg').once('value', function(snapshot) {
var user = snapshot.val();
ref.child('Blogs/'+user+'/blogs').once('value', function(blogSnapshot) {
var daBlog = blogSnapshot.val();
});
});
You might also want to reconsider if you can restructure your data to better fit your use-case and Firebase's limitations. They have some good documentation on structuring your data, but the most important one for people new to NoSQL/hierarchical databases seems to be "avoid building nests".
Also see my answer on Firebase query if child of child contains a value for a good example. I'd also recommend reading about many-to-many relationships in Firebase, and this article on general NoSQL data modeling.
Given your current data structure you can retrieve the User that contains the blog post you are looking for.
const db = firebase.database()
const usersRef = db.ref('users')
const query = usersRef.orderByChild('blogs/efg').limitToLast(1)
query.once('value').then((ss) => {
console.log(ss.val()) //=> { '7654321': { blogs: {...}}}
})
You need to use limitToLast since Objects are sorted last when using orderByChild docs.
It's actually super easy - just use foreslash:
db.ref('Users').child("userid/name")
db.ref('Users').child("userid/blogs")
db.ref('Users').child("userid/blogs/abc")
No need of loops or anything more.

Insert multiple records and/or update specific fields and return only new records inserted (MongoDB)

Hi I have a collection as follows
var articles = [
{
"title": "Article title1",
"content": "Article ... content......... 1. ",
"url": "http://matt.wordpress.com/article/X",
"last_fetched_time": new Date();
},
{
"title": "Article title2",
"content": "Article ... content......... 2. ",
"url": "http://matt.blogger.com/article/Y",
"last_fetched_time": new Date();
}
];
db.collection('articles').insert(articles, {safe:true}, function(err, result) {}); //articles collection created
I want to fetch blog feeds from multiple endpoints in parallel periodically and add new articles into the collection and update the last fetched date-time field of the existing articles in the collection. If I'm not asking too much I also want the upsert's callback returns only the new articles inserted.
//fetch articles periodically
fetchArticles = function(req, res) {
async.parallel([
//fetch word press endpoint
//get "title", "content", "url"
//set last_fetched_time with new Date();
//fetch blogger endpoint
//get "title", "content", "url"
//set last_fetched_time with new Date();
],
function(err, results) {
//merge results[0] and results[1] in a batch =[]
//if the article url is not already in the collection, insert article into the articles collection
//if the article url is found in the collection, update article because last_fetched_time changed
//finally return only new inserted articles, not updated ones
db.collection('articles').update(batch, {safe:true, upsert : true}, function(err, result) {
//result = only new articles inserted
});
});
}
url field should be unique and I did
db.articles.ensureIndex({"url":1}, {unique: true, sparse:true, dropDups: true});
The problem is this code doesn't insert new articles
You seem to have your functions mixed around even though I clearly see what you are trying to do.
Your batch you are passing in contains an array of documents that you want to insert/update. The problem is that this functionality is only available to the insert method.
Since you are using the update method, the option to pass in an array of documents for batch processing is not available. Updates with upsert set as you have done are intended to be issued with the primary arguments of a selector and a single 'document'. The idea being that where the selector matches an existing document, that document is updated with the details in document. In the event the match is not found, then a new document is then inserted.
Additionally as you have not used, there is the multi option that can be applied. It's purpose is that when the selector matches more than one document, then the changes are applied to all of the matching documents. Unspecified the behavior is considered to be false and only the first matching document found will be updated.
It would seem that though you wish to have this accompanied by a batch processing functionality, it does not presently exist. There is a JIRA you can follow / support for this.
https://jira.mongodb.org/browse/SERVER-2172
Refer to the links for the functions in the documentation, which explains all the available arguments and options. Also see the shell documentation for a detailed explaination of the options:
http://docs.mongodb.org/manual/reference/method/db.collection.update/

Resources