Form's field modified date - sharepoint

My Teams form has several fields including [Status]. I want to add filed showing date-time of the last change of the [Status] but only field formulas could be used. Are there any functions or accessible form properties that would allow capturing modification of [Status] while ignoring all other changes?

you can create a new workflow on editing an item and then check if the status is changed or not and then if yes, update the "lastStatusUpdatedDate", with Nintex workflow it's easy.

or you can use this api to get versions and filter what you want:
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl +
"/_api/web/Lists/getbytitle('JobTitles')/items(1)/versions?$select=Title,VersionLabel",
async: false,
headers: {
'accept': 'application/json;odata=nometadata'
},
complete: function(request) {
console.log("CurrentUser: " + JSON.stringify(request, null, 4));
},
error: function(request) {
console.log(JSON.stringify(request, null, 4));
}
});
the result is sth like this:
{
"value": [
{
"Title":"Web Developer",
"VersionLabel":"2.0"
},
{
"Title":"Application Developer",
"VersionLabel":"1.0"
}
]
}

Related

Change entertainment area via Hue Sync Box API

I am leveraging the Hue Sync Box API and I am able to control the settings like sync mode, and intensity. However, I am unable to change hueTarget to change the entertainment area in use.
This is my request:
PUT https://hue_sync_box_ip/api/v1/execution
Headers:
'Content-Type': 'application/json; charset=utf-8'
'Authorization': 'Bearer <token>'
Body:
{"hueTarget": "/groups/c5cecc67-52e8-4f48-9d8d-433634daa9a1"}
The response I get is a 400 error with this body
{"code":15,"message":"Invalid Value"}
As per documentation, this is the problem:
The key exists and the value type matches, but it is not according to the specified format or range.
The documentation on hueTarget is this:
hueTarget
Get, Put
string, enum
Currently selected entertainment area (/groups/ for entertainment group on bridge api v1, and entertainment configuration in UUID format for bridge api v2)
The method is put, the key is valid as per error message, the value type matches string, and I am following the /groups/<id> that is required on v1.
These are my groups. The id I've used matches the "Streaming" which is the group (entertainment area) to which I was trying to change.
...
"hue": {
"bridgeUniqueId": "001788FFFE6A3B07",
"bridgeIpAddress": "<redacted>",
"groupId": "ef023ba4-71bc-4b8b-a7ad-f86dd68356a4",
"groups": {
"ef023ba4-71bc-4b8b-a7ad-f86dd68356a4": {
"name": "Living Room TV",
"numLights": 5,
"active": false
"active": true
},
"c5cecc67-52e8-4f48-9d8d-433634daa9a1": {
"name": "Streaming",
"numLights": 3,
"active": false
}
},
"connectionState": "connected"
},
...
I have also tried leveraging the hue endpoint with the same results:
This is my request:
PUT https://hue_sync_box_ip/api/v1/hue
Headers:
'Content-Type': 'application/json; charset=utf-8'
'Authorization': 'Bearer <token>'
Body:
{
"groups":
{
"c5cecc67-52e8-4f48-9d8d-433634daa9a1": {
"active": true
}
}
}
The response I get is a 400 error with this body
{"code":15,"message":"Invalid Value"}
This matches the documentation: groups/<id>/ active Get, Put boolean.
I am also able to set the entertainment area manually on the app.
Any thoughts on what could be the issue here? I do think this code used to work at some point, but I am not sure as to confirm it for certain.
I've managed to make it work. Instead of sending /groups/<id> as per documentation, you should only send <id>.
In other words, the body of the first call should be:
{"hueTarget": "c5cecc67-52e8-4f48-9d8d-433634daa9a1"}
instead of the original
{"hueTarget": "/groups/c5cecc67-52e8-4f48-9d8d-433634daa9a1"}

How to Update properties of a OneDrive item using REST API?

I am trying to update the properties of a OneDrive item using SharePoint REST API.
OneDrive item web URL:
https://vx13-my.sharepoint.com/personal/alexw_vx13_onmicrosoft_com/Documents/SrcDir/File-To-Update.txt
Mainly looking to updating following fields: Author, Created_x0020_By, Editor, Modified_x0020_By, Modified, Created
I tried using Graph API:
Request:
Method: PATCH |
URL: https://graph.microsoft.com/v1.0/sites/vx13-my.sharepoint.com,eab581b1-a945-4d23-9c8e-ec67bb74a42d,32fa1468-54b6-40d6-abbd-f775c4c3932b/drives/b!sYG16kWpI02cjuxnu3SkLWgU-jK2VNZAq733dcTDkyvIAAMdpSy_Sryiw8ARQ8Gv/root:/SrcDir/File-To-Update.txt:/listItem/fields |
Header:
Content-Type: application/json |
Accept: application/json;odata=verbose |
Body:
{
"Created": "2019-02-01 10:25 AM",
"Modified": "2020-01-27 11:25 AM",
"Modified_x0020_By": "3",
"Created_x0020_By": "3",
"Author": "Alex Wilber",
"Editor": "Alex Wilber"
}
It is giving failure response as:
{"code": "accessDenied", "message": "Field 'Created' is read-only"}
Through CSOM API using ValidateUpdateListItem() its working & successfully updating the property fields of OneDrive items.
But is there any way to update property fields of OneDrive item through REST API?
By default, these properties are Readonly by and cannot be edited.
You need to set the ReadOnlyField to false to update these fields. I used to answer the same question here: https://learn.microsoft.com/en-us/answers/questions/221106/rest-api-to-create-item-with-custom-created-by-and.html
For Created By column:
Url: /_api/web/lists/getbytitle('Mylist')/fields/getbytitle('Created By')
Body:
{
"__metadata": { "type": "SP.FieldUser"},
"ReadOnlyField": false
}
For Created column:
Url: /_api/web/lists/getbytitle('Mylist')/fields/getbytitle('Created')
Body:
{
"__metadata": { "type": "SP.FieldDateTime"},
"ReadOnlyField": false
}
Using SharePoint REST API,
a work around to update the Properties of OneDrive item using method ValidateUpdateListItem()
Get the list-item-id of the file
GET https://vx13-my.sharepoint.com/personal/alexw_vx13_onmicrosoft_com/_api/web/GetFileByServerRelativePath(decodedurl='/personal/alexw_vx13_onmicrosoft_com/Documents/SrcDir/File-To-Update.txt')/listitemallfields/fieldvaluesastext?$select=Id
Update Author, Editor, Created & Modified fields of list item using ValidateUpdateListItem
POST https://vx13-my.sharepoint.com/personal/alexw_vx13_onmicrosoft_com/_api/web/Lists/GetByTitle('Documents')/items(<list-item-id>)/ValidateUpdateListItem()
Content-Type:application/json
Accept:application/json;odata=verbose
Body:
{
"formValues":
[
{
"FieldName": "Created",
"FieldValue": "2019/02/01 10:25 AM"
},
{
"FieldName": "Modified",
"FieldValue": "2020/01/27 11:25 AM"
},
{
"FieldName": "Author",
"FieldValue": "[{'Key':'i:0#.f|membership|test_user_AK#vx13.onmicrosoft.com'}]"
},
{
"FieldName": "Editor",
"FieldValue": "[{'Key':'i:0#.f|membership|test_user_JV#vx13.onmicrosoft.com'}]"
}
],
"bNewDocumentUpdate": true
}
If you refer to the documentation here under the Properties section, you will notice certain fields are read only and you wont be able to update them using Graph API.
For all other properties(e.g. name), follow this documentation to update.
Being said that, you can always request for a feature by filling a User Voice so that it goes into our backlog.

How to build a NodeJS variable to create a regexp query for ElasticSearch

I'm working at a company that used to have a monolithic PHP/MySQL CMS which controlled the website, but we are now trying to get the website to pull data from our API rather than directly from MySQL. The API is simply ElasticSearch on AWS. I wrote some code which now moves our data from MySQL to ElasticSearch. And now I can get the data I want with a curl call like this:
curl --verbose -d '{"from" : 0, "size" : 10000, "query": { "bool": { "should": [ { "regexp": { "string-of-words-associated-with-this-document": { "value": ".*steel.*" } } }, { "regexp": { "string-of-words-associated-with-this-document": { "value": ".*services.*" } } } ] } } }' -H 'Content-Type: application/json' -X GET "https://search-sameday01-ntsw7b7shy3wu.us-east-1.es.amazonaws.com/crawlers/_search?pretty=true"
This works great. Each document in ElasticSearch has a field that contains the words we want to query against, and we match against that field using regexp queries.
Now I'm writing a new app that checks data coming in from our web crawlers, and looks to see if we have certain names already in our database. The new app is a NodeJS app, so I decided to use this library:
https://github.com/elastic/elasticsearch-js
I need to build up what might be many regexp clauses, so I go into a loop and build up many clauses in an array:
array_of_elasticsearch_clauses_should_match.push( { "regexp": { "string-of-words-associated-with-this-document": { "value": ".*" + word_sanitized + ".*" } } } );
So I thought I could then pass in this variable like this:
es_client.search({
index: 'crawlers',
type: 'sameday',
body: {
query: {
bool: {
should: array_of_elasticsearch_clauses_should_match
}
}
}
}).then(function (resp) {
But I get this error:
Trace: [parsing_exception] [array_of_elasticsearch_clauses_should_match] query malformed, no start_object after query name, with { line=1 & col=75 }
How could I build up the regexp clauses in a variable and then pass it in?

id cannot be used in graphQL where clause?

{
members {
id
lastName
}
}
When I tried to get the data from members table, I can get the following responses.
{ "data": {
"members": [
{
"id": "TWVtYmVyOjE=",
"lastName": "temp"
},
{
"id": "TWVtYmVyOjI=",
"lastName": "temp2"
}
] } }
However, when I tried to update the row with 'id' where clause, the console shows error.
mutation {
updateMembers(
input: {
values: {
email: "testing#test.com"
},
where: {
id: 3
}
}
) {
affectedCount
clientMutationId
}
}
"message": "Unknown column 'NaN' in 'where clause'",
Some results from above confused me.
Why the id returned is not a numeric value? From the db, it is a number.
When I updated the record, can I use numeric id value in where clause?
I am using nodejs, apollo-client and graphql-sequelize-crud
TL;DR: check out my possibly not relay compatible PR here https://github.com/Glavin001/graphql-sequelize-crud/pull/30
Basically, the internal source code is calling the fromGlobalId API from relay-graphql, but passed a primitive value in it (e.g. your 3), causing it to return undefined. Hence I just removed the call from the source code and made a pull request.
P.S. This buggy thing which used my 2 hours to solve failed in build, I think this solution may not be consistent enough.
Please try this
mutation {
updateMembers(
input: {
values: {
email: "testing#test.com"
},
where: {
id: "3"
}
}
) {
affectedCount
clientMutationId
}
}

Azure Storage Table Query - result vs response

I'm using node.js as my Server and have an account on Azure where my storage table resides. I'm retrieving all records for a specific partition by using the following :
var query= new azure.TableQuery().where('PartitionKey eq ?',username);
tableSvc.queryEntities(localTableName,query, null, function(error, result, response) {
}
When this call comes back, I want to access the values for the rest of the fields of table. But when I do that using result.entries, it kinda looks weird. Alternatively I think I can access the results via response.body.value.userID.
Here is how the structure of "result.entries" vs "response" object looks like:
result.entries :
[ { PartitionKey: { '$': 'Edm.String', _: '048tfbne' },
RowKey: { '$': 'Edm.String', _: '145610564488450166' },
Timestamp:
{ '$': 'Edm.DateTime',
_: Mon Feb 22 2016 01:47:26 GMT+0000 (UTC) },
username: { _: '048tfbne' },
userID: { _: '145610564488450166' },
deleteAfter: { _: 'not set yet' },
'.metadata': { etag: 'W/"datetime\'2016-02-22T01%3A47%3A26.4394133Z\'"' } } ]
response :
{ isSuccessful: true,
statusCode: 200,
body:
{ 'odata.metadata': 'https://photoshareuserdata.table.core.windows.net/$metadata#userIdentifier',
value:
[ { 'odata.etag': 'W/"datetime\'2016-02-22T01%3A47%3A26.4394133Z\'"',
PartitionKey: '048tfbne',
RowKey: '145610564488450166',
Timestamp: '2016-02-22T01:47:26.4394133Z',
username: '048tfbne',
userID: '145610564488450166',
deleteAfter: 'not set yet' } ] },
I thought results.entries would be a better way to access the records, but I am sort of weirded out by the nested objects and Edm.String here.
Which is a better way to access the records ?
Table Node Sample shows how to access entities in a table as result of a query. See method "runPageQuery".
Actually, according the official Section: Query a set of entities, there is a paragraph as following:
If successful, result.entries will contain an array of entities that match the query. If the query was unable to return all entities, result.continuationToken will be non-null and can be used as the third parameter of queryEntities to retrieve more results.
And we also can refer to the sample at Azure-storage-for-node repository on GitHub. Which has told us the answer.

Resources