I've many small tables under IndexedDB, each to create a select in my HTML page.
So let's say one is created with:
store_dest_fam.createIndex("tdestf_id", "tdestf_id", { unique: true });
store_dest_fam.createIndex("tdestf_nom", "tdestf_nom", { unique: false });
a second one is:
store_frota.createIndex("tfrota_id", "tfrota_id", { unique: true });
store_frota.createIndex("tfrota_nom", "tfrota_nom", { unique: false });
If I create a function for each, in order to read value using "cursor" I build a loop in which I have:
var tdestf_id = cursor.value.tdestf_id;
var tdestf_nom = cursor.value.tdestf_nom;
and so on. That's OK.
But as I've many small tables, I want to create a "global function", with parameters like:
make_select(name_of_table,name_for_value,name_for_text);
with for example:
name_of_table = "TAB_START"; // Name of the table to search in
name_for_value = "tdestf_id"; // Name of the field which value would be use as "value" in the select-option
name_for_text = "tdestf_text"; // Name of the field which value would be use as "text" in the select-option
I can open the connection to the table using
var tx_menu = db_handle.transaction(name_of_table, 'readonly');
var store_menu = tx_menu.objectStore(name_of_table);
which is logical as db_handle.transaction wait for the "string name" of the table, which is what i'm providing. But in the cursor loop this don't work (which seem to be logical as curso need a pointer to its structure while I'm providing a string)
var data_value = cursor.value.name_for_value;
var data_text = cursor.value.name_for_text;
So th question is: how can I get the cursor item value, giving the "string name" of the field?
Are you asking how to dynamically access cursor.value.somethinghere? If so, you can use bracket notation. Assuming your asked for a fields tsestf_id and tdestgf_text and passed them as valueField and textField:
var data_value = cursor.value[valueField];
var data_text = cursor.value[textField];
Related
What I want to do is change the url.
Replace the Object word with an event parameter called e1.
Replace the word field with the event parameter e2.
I know this code is not working.
But I don't know how to do it.
The following is my code that I just wrote.
function getAllFieldValue(e1,e2) {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var url = 'test123.my.salesforce.com/services/data/v44.0/queryAll?q=SELECT Field FROM Object';
var url = url.replace('Object',e1);
var url = url.replace('Field',e2);
var response = UrlFetchApp.fetch(url,getUrlFetchOptions());
var json = response.getContentText();
var data = JSON.parse(json);
var fieldValues = data.records;
for(var i=0;i<fieldValues.length;i++){
var fieldValue = fieldValues[i].e;
ss.getRange(i+1,1).setValue(fieldValue);
}
}
I want to take the data from another database through this code and put it in the Google spreadsheet.
For e1, it means the object value selected in the dropbox.
For e2, it means the field of the object selected in the drop box.
Is there a way to use two event parameters for one function?
I look forward to hearing from you.
====================
Please understand that I am using a translator because I am not good at English.
Checking fieldValues[i] in Logger.log returns the following values:
[{
attributes={
type=Account,
url=/services/data/v44.0/sobjects/Account/0015i00000BS03VAAT
},
Name=University of Arizona
},
{
attributes={
type=Account,
url=/services/data/v44.0/sobjects/Account/0015i00000BS03TAAT
},
Name=United Oil & Gas Corp.
},
{
attributes={
type=Account,
url=/services/data/v44.0/sobjects/Account/0015i00000BS03ZAAT
},
Name=sForce
}]
The issues I am currently experiencing are as follows.
If I select 'Name' from the drop-down list, ec2 becomes 'Name'.
As far as I'm concerned,
var fieldName = fieldValues[i].e2 is
var fieldName = fieldValues[i].Name
It means that.
I think fieldValues[i].e2 should return the values of University of Arizona, United Oil & Gas Corp, sForce.
But in reality nothing is returned.
var fieldName = fieldValues[i].Name works properly.
I think there is a problem with fieldValues[i].e2
This is the problem I'm currently experiencing.
There was no problem with the parameters e1, e2, which I thought was a problem. The reason why the code did not work is because of the for loop var fieldValue = fieldValues[i].e; Because it didn't work properly.
var fieldName = fieldValues[i].e2
to
var fieldName = fieldValues[i][e2]
After modifying it like this, the code works properly.
Im trying to update an SP.Listitem withholding an spUser with another user with the use of JSOM. See codesnippet bellow
// Query the picker for user information.
$.fn.getUserInfo2 = function () {
var eleId = $(this).attr('id');
var siteUrl = _spPageContextInfo.siteServerRelativeUrl;
var spUsersInfo = GetPeoplePickerValues(eleId);
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('VLS-dokument');
var itemArray = [];
for(i=0;i<$.miniMenu.i.results.length;i++)
{
var item = $.miniMenu.i.results[i];
var oListItem = oList.getItemById(item.Id);
oListItem.set_item('Informationsägare', SP.FieldUserValue.fromUser(spUsersInfo.Key));
oListItem.update();
itemArray.push(oListItem);
clientContext.Load(itemArray[itemArray.Length - 1]);
}
clientContext.executeQueryAsync(Function.createDelegate(this, function () { alert(""); }), Function.createDelegate(this, function () { alert(""); }));
return spUsersInfo; //.slice(0, -2)
}
spUsersInfo contains the user obj, peoplePicker.GetAllUserInfo()
The return off SP.FieldUserValue.fromUser(spUsersInfo.Key) to be the problem since the app crash reaching that line oListItem.set_item('Informationsägare', SP.FieldUserValue.fromUser(spUsersInfo.Key));
What part of the user obj is supposed to be passed into SP.FieldUserValue.fromUser(spUsersInfo.Key) if not the key?
Is there another way to do it?
People picker columns are really just lookup columns, looking up against the site collection's user information list. You can set a lookup column either by specifying the ID of the desired item in the lookup list, or by creating a special lookup field value object (letting SharePoint do the work of finding the ID, given the desired text value).
According to the documentation the value passed to SP.FieldUserValue.fromUser() should be the user's name as a string. In practice, this should be the user's display name from the user information list.
So if you don't know the user's lookup ID, but do know their display name, you would use this: oListItem.set_item('Informationsägare',SP.FieldUserValue.fromUser(username));
If you didn't know the user name, but did know the lookup ID of the user, you could instead pass that number to item.set_item() directly, i.e. oListItem.set_item('Informationsägare',lookupId);.
If the spUsersInfo.Key value from your GetPeoplePickers() method is in the format of i:0#.w|Cool Person then you can split that value and just get the string Cool Person to feed into SP.FieldUserValue.fromUser().
Currently I have a form with 10 fields that I need to do sendkeys > store the value and after assert this value when save the form. For each of these fields I need to create a function and store the value in a variable or is there a better way?
My actual code:
var email = driver.findElement(By.name('email'));
email.sendKeys('info#domain.com');
email.getAttribute("value").then(function(email_text) {
var email = email_text;
});
Cheers,
Rafael
If I understand correct, the process looks like you should fill some fields, remember their values and check values after the form has been submitted.
There is no one standard decision for tasks like this, it depends on developer.
So, we know which values we need and can store it for example in map
{
'email':'example#email.com',
'telephone':111222333
}
Key is name for finding element, value - for sendKey and checkValue methods.
You should write two methods, which will work with test data map and will fill inputs and check values in cycle by map keys.
Do you mean you want to do this as an array?
// you can represent each field as an object
var fields = [
{ elementName: 'email', expectedText: 'info#domain.com' },
{ elementName: 'password', expectedText: 'bla bla bla' }
];
// sendKeys to each field with the specified text
fields.forEach(function(field) {
browser.driver.findElement(by.name(field.elementName)).sendKeys(field.expectedText);
});
// to get all the field text (from promises) and store it as an array
browser.controlFlow().execute(function() {
var textArray = [];
fields.forEach(function(field) {
browser.driver.findElement(by.name(field.elementName)).getAttribute('value').then(function(actualText) {
textArray.push({elementName: field.elementName, actualText: actualText});
});
});
return textArray;
}).then(function(storedTextArray) {
// do something with the stored text array here
});
Related to: mongodb/meteor collection check if subdocument field exists when field is a variable
I'm trying to query a Meteor collection by building an object with some variable field names. This works when the object has one field, for example
var query = {};
query['myField.'+myVariable] = {$exists: true};
Collection.find(query); //works fine
But I need to query with multiple selectors. For example, I need to check that a field name with a variable exists, and also check if some other field = true, and if some other field = a variable. So I'm trying to find a general way to build query objects. I have tried the following:
var query = {};
query['myField.'+myVariable] = {$exists: true};
query[newField] = false;
Collection.find(query);
This doesn't work. I'm not sure if that's because the 'newField' is not of type Object or something.
I've tried also using the $and selector to see if that works but I don't think the syntax I'm using is exactly correct...
var query = {};
var object = {};
object['myField'.+myVariable] = {$exists: true};
query['$and'] = [object, {newField: false}];
Collection.find(query);
This also doesn't work. I was trying to build with the mongo $and selector which works by using an array.
How do I syntactically build a Meteor collection query with javascript object notation and object literals? I feel like either one of these should work.
To be specific, I'm looking for the following (semi pseudocode since getting a subdocument/subobject with dot notation doesn't work with a mongo query)
Collection.find({correlated: false, readBy.(Meteor.userId()): {$exists: true} ...)
I also thought this should work:
var query = {};
query['myField.'+myVariable] = {$exists: true};
Collection.find(query, {otherField: false})
//OR
var query2 = {};
query['priority'] = false;
Collection.find(query, query2)
But neither of them do.
EDIT: example doc. I want to find the document such that the current user ID is NOT a readBy field AND has correlated: false
{
"_id" : ObjectId("55b6868906ce5d7b1ac6af10"),
"title" : "test",
"correlated" : "false",
"readBy" : {
"DXqLhesDEJq4ye8Dy" : ISODate("2015-07-27T18:29:43.592Z")
}
}
There is only one selector argument to a find. So this:
Collection.find(query, {otherField: false})
is not correct. query would have to contain the information about otherField. Have a close look at this example code:
// 'readBy.abc123'
var key = 'readBy.' + Meteor.userId();
// build the selector by parts
var selector = {correlated: false};
selector[key] = {$exists: false};
// selector should now be something like:
// {correlated: false, 'readBy.abc123': {$exists: false}}
// note that these are ANDed together so all conditions must be true
// here's a cursor you can use to fetch your documents
var cursor = Collection.find(selector);
// log one of the selected documents
console.log(Collection.findOne(selector));
I can take record from store: var record = store.getAt(i);
But if i want to take fileds which have a same name from record i get only first field value. For example if i have XML with:
Code:
<zem>
<parcel>
....
<parcel>
<really>
<price>555.555<price>
</really>
<really>
<price>666.666<price>
</really>
</zem>
And using record.get("price") i can get only 555.555 value.
Its possible to get values of all fields of <really>? Or array of values of all fields with name=<price>?
Take a walk on store:
var res = [];
store.each(function(record) { res.push(record.get('price')); })