How to retrieve a calculated column value using sp.web SPFX - spfx

I am creating an SPFX (ReactJS/TypeScript) webpart and using:
let docs = sp.web.lists.getByTitle("Case Documents").items.select("ID","Title","CaseID").orderBy("Modified", true).get();
to attempt to retrieve column values from a SharePoint DOC library.
CaseID is a lookup column looking at an SP list. There are values in the lookup column populated from that other list.
I can get Id and Title values from the library but not CaseID (lookup column).
I get this error:
Uncaught (in promise) Error: Error making HttpClient request in queryable [400] ::>
{"odata.error":{"code":"-1, Microsoft.SharePoint.SPException","message":
{"lang":"en-US","value":"The query to field 'CaseID' is not valid.
The $select query string must specify the target fields and the $expand query string must contains CaseID."}}}
at new HttpRequestError (parsers.js:130)
at Function.<anonymous> (parsers.js:145)
at step (tslib.es6.js:99)
at Object.next (tslib.es6.js:80)
at fulfilled (tslib.es6.js:70)
HttpRequestError # parsers.js:130
(anonymous) # parsers.js:145
step # tslib.es6.js:99
(anonymous) # tslib.es6.js:80
fulfilled # tslib.es6.js:70
Any ideas what could be causing this?

you can get lookup values for your lookup column value by:
let docs = sp.web.lists.getByTitle("Case Documents").items.select("ID","Title","CaseID/Title", "CaseID/ID").expand("CaseID").orderBy("Modified", true).get();

Related

Laravel 8, MySQL - Search JSON column if it is empty

I have a table with JSON column which can be empty, or if it is not empty it is possible not to have the key. I am trying following query for updates:
Award::where('background->logo', 'name')
->update(['background->logo' => null]);
I am getting following error:
SQLSTATE[22032]: <<Unknown error>>: 3141 Invalid JSON text in argument 1 to function json_extract: \"The document is empty.\" at position 0. (SQL: update `awards` set `background` = json_set(`background`, '$.\"logo\"', ?), `awards`.`updated_at` = 2022-04-11 11:13:53 where json_unquote(json_extract(`background`, '$.\"logo\"')) = 4ppcNtOGsTzzkNlv.png and `awards`.`deleted_at` is null)"
Background column can be null, and the logo key can be absent.
What I am doing wrong? Is it possible to update JSON columns like this?

Update json column value in eloquent model in laravel - Database-Oracle

In my project current_profile is a JSON object column for EmployeePromotionAndShifting model. I want to update a key named division_i of current_profile column.
The JSON object is like this:
"current_profile" =>
{"staff_id":"2927","division_id":"84","department_id":"200","unit_id":null}
I am getting an error:
"This database engine does not support JSON operations." at
vendor\yajra\laravel-oci8\src\Oci8\Query\Grammars\OracleGrammar.php:1
Code to update in database!
EmployeePromotionAndShifting::where('staff_id',$currentProfile['staff_id'])->update(['current_profile->division_id' => 555,]);
I want to update division_id key of current_profile column for a particular row.

Error when trying to query by file id in GAPI Drive v3 using Python's library

I'm using service.files().list() and providing a query string to retrieve files that match the ids in a given list. Yet Calling service.files.list errors out, and GAPI returns an error code of 400. I'm using a service object created using an access token.
I get the following message:
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files?pageSize=50&fields=%2A&q=id+contains+%271234%27&spaces=drive&alt=json returned "Invalid Value". Details: "Invalid Value">
Here's the code. Is it possible to query by file id in the list API? I prefer to do it this way instead of making a get request for each individual file.
# Create file query string
queryStr = ""
for i in range(len(fileIds)):
queryStr += f"id='{fileIds[i]}'"
if i != len(fileIds) - 1:
queryStr += " or "
# Build files array
results = service.files().list(
pageSize=50,
fields="*",
q=queryStr,
spaces="drive"
).execute()
print(results.get("files", [0])[0])
You appear to be trying to search on id contains
If you check the documentation File query terms
You will find that Id is not a searchable field.
Try something like name contains car for example

Django rest framework mongoengine update new field with default value

I'm using Django rest framework mongoengine after created few documents, if i want add a new field with default value. Is there any way to do that orelse i need to update with few custom function.
Note: I want to fetch the data with filter having a new field name. That time the field is not there. So i'm getting empty.
From what I understand, you are modifying a MongoEngine model (adding a field with a default value) after documents were inserted. And you are having issue when filtering your collection on that new field.
Basically you have the following confusing situation:
from mongoengine import *
conn = connect()
conn.test.test_person.insert({'age': 5}) # Simulate an old object
class TestPerson(Document):
name = StringField(default='John') # the new field
age = IntField()
person = TestPerson.objects().first()
assert person.name == "John"
assert Test.objects(name='John').count() == 0
In fact, MongoEngine dynamically applies the default value when the field of the underlying pymongo document is empty but it doesn't account for that when filtering.
The only reliable way to guarantee that filtering will work is to migrate your existing documents.
If its only adding a field with a default value, you could do this with MongoEngine: TestPerson.objects().update(name='John')
If you did more important/complicated changes to your document structure, then the best option is to get down to pymongo.
coll = TestPerson._get_collection()
coll.update({}, {'$set': {'name': 'John'}})

ActiveRecord search returns 'Syntax error or access violation' error

In my Yii application, I have a model that represents siteconfig table and have four columns:
integer config_id,
string key,
string value,
string update_time.
I created a model using Gii (to ensure that I will not make any mistakes). I don't publish entire code here, cause this is 100% unmodified by me, standard model code generated by Gii. Since my problem is related to search, I only publish important part of generated code (the search() method):
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('config_id',$this->config_id);
$criteria->compare('key',$this->key,true);
$criteria->compare('value',$this->value,true);
$criteria->compare('update_time',$this->update_time,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
I'm trying to use generated model in normal Yii ActiveRecord search like that:
$etona = new SiteConfigurationRecord();
$crit = new CDbCriteria();
$crit->select = "value";
$crit->condition = "key=:key";
$crit->params = array(":key"=>"sitename");
$etona = $etona->find($crit);
But, instead of getting expected search results, a strange (for me) error occurs:
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]:
Syntax error or access violation: 1064 You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'key='sitename' LIMIT 1' at line 1.
The SQL statement executed was: SELECT value FROM siteconfig t
WHERE key=:key LIMIT 1
Where did I go wrong?
You used key for column name, which is a reserved word in MySQL. Yii uses table alias in queries, but does not take any special care in case of reserverd word used as columns names. So, you have to take care of this by yourself.
For example:
$etona = new SiteConfigurationRecord();
$crit = new CDbCriteria();
$crit->select = "value";
$crit->condition = "t.key=:key"; // 't' is default alias
$crit->params = array(":key"=>"sitename");
$etona = $etona->find($crit);
This should solve your problem.
As #Dmitry explained, SQL doesn't allow you to use the column name key. The Yii call in the code in your answer works because Yii performs parameter binding automatically, using names other than reserved words for the parameters. And it also uses fully-qualified column names (prefixes all column name references with <tablename>., regardless of what invalid column name (reserved words) you pass the findByAttributes method.
now it works.. ^^
i just use this code...
$etona = SiteConfigurationRecord::model()->findByAttributes(array('key'=>'sitename'));
maybe i need to study activerecord more somehow...
but still i don't know why the code above doesn't work

Resources