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().
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.
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];
Context
In a Firebase DB I'm storing "events" and "users". Users can have favorite events, to manage them I only store the event's id in the favorite user's DB location. So to grab favorite events informations, I need to firstable grab the event id and then go to the DB events location, to collect all the datas I need.
Problem
I would like to store in an Array all the favorite events informations (each event would be an Object with inside it : "key" : "value"), to use that Array in my HTML view and print the informations. But it doesn't work the way I coded it... :(
// This ref is too grab favorite event id (in my case only 2) in the user DB location
var refUserFavoris = firebase.database().ref().child("users/"+user.uid+"/events/favoris");
$scope.favorisTmp = $firebaseArray(refUserFavoris);
// This shows one array, with two objects (wich are my two user's favorite events) wich include ids
console.log($scope.favorisTmp);
// This is to load the objects and with the foreEach, grab there ids to use them in the next ref call
$scope.favorisTmp.$loaded().then(function()
{
angular.forEach($scope.favorisTmp, function(favoris)
{
// This shows two lines : the id of each object
console.log(favoris.$id);
// Call a new ref to reach the event informations (in a different location of the DB) using the previous id
firebase.database().ref("events/"+favoris.$id).once('value').then(function(snapshot)
{
// Attempt to store events datas for each id I have (in my case, only two)
snapshot.forEach(function(favorisSnap)
{
var favSnap = favorisSnap.val();
// This shows a lot of "undefined" lines, wich I don't want. I would like two objects, with all informations inside
console.log(favSnap.nbPersonne);
// $scope.favorisF is an Array that I would like to use in a ng-repeat to print all datas for each event
// For now this doesn't show anything
$scope.favorisF = favSnap;
});
// If using favSnap out of the previous function, I got a "favSnap" is undifined error
console.log(favSnap);
});
});
});
<ion-item ng-repeat="f in favorisF" class="item-avatar">
{{f.nbPersonne}}
</ion-item>
EDIT 1 :
I tried a new way to have my data, but a new problem came, how to fill an Array inside a loop ? I've tried "push" and "$add" methods, but no one worked. Any ideas ?
var newFav = [];
var user;
user = firebase.auth().currentUser;
var refUserFavoris = firebase.database().ref().child("users/"+user.uid+"/events/favoris");
$scope.favorisTmp = $firebaseArray(refUserFavoris);
$scope.favorisTmp.$loaded().then(function()
{
angular.forEach($scope.favorisTmp, function(favoris)
{
console.log(favoris.$id);
var refFavoris = firebase.database().ref("events/"+favoris.$id);
refFavoris.on('value', function(snap)
{
//This is where I'm trying to fill "newFav" in each steps of the loop
newFav.push(snap.val());
console.log("Scope newFav vaut :", $scope.newFav);
});
});
});
I think you made a typo here.
var refUserFavoris = firebase.database().ref("events/favoris/"+favoris.$id).once('value')
Thanks a lot Abdel, I fixed my problem :
Here is the solution
$scope.newFav = [];
console.log($scope.newFav);
$scope.favorisTmp.$loaded().then(function()
{
angular.forEach($scope.favorisTmp, function(favoris)
{
console.log(favoris.$id);
var refFavoris = firebase.database().ref("events/"+favoris.$id);
refFavoris.on('value', function(snap)
{
$scope.newFav.push(snap.val());
console.log("Scope newFav vaut :", $scope.newFav);
});
});
});
I have data being sent to a custom data list from the following code:
// Get the site name and dataLists
var site = siteService.getSite("Testing");
var dataLists = site.getContainer("dataLists");
// Check for data list existence
if (!dataLists) {
var dataLists = site.createNode("dataLists", "cm:folder");
var dataListProps = new Array(1);
dataListProps["st:componentId"] = "dataLists";
dataLists.addAspect("st:siteContainer", dataListProps);
dataLists.save();
}
// Create new data list variable
var orpList = dataLists.childByNamePath("orplist1");
// If the data list hasn't been created yet, create it
if (!orpList) {
var orpList = dataLists.createNode("orplist1","dl:dataList");
// Tells Alfresco share which type of items to create
orpList.properties["dl:dataListItemType"] = "orpdl:orpList";
orpList.save();
var orpListProps = [];
orpListProps["cm:title"] = "Opportunity Registrations: In Progress";
orpListProps["cm:description"] = "Opportunity registrations that are out for review.";
orpList.addAspect("cm:titled", orpListProps);
}
// Create new item in the data list and populate it
var opportunity = orpList.createNode(execution.getVariable("orpWorkflow_nodeName"), "orpdl:orpList");
opportunity.properties["orpdl:nodeName"] = orpWorkflow_nodeName;
opportunity.properties["orpdl:dateSubmitted"] = Date().toString();
opportunity.properties["orpdl:submissionStatus"] = "Requires Revisions";
opportunity.save();
This correctly creates data list items, however, at other steps of the workflow require these items to be updated. I have thought of the following options:
Remove the data list item and add another with the updated information
Simply update the data list item
Unfortunately I have not found adequate solutions elsewhere to either of these options. I attempted to use orpWorkflow_nodeName, which is a unique identifier generated at another step, to identify a node to find it. This does not seem to work. I am also aware that nodes have unique identifiers generated by Alfresco itself, but documentation doesn't give adequate information on how to obtain and use this.
My question:
Instead of var opportunity = orpList.createNode(), what must I use in
place of createNode() to identify an existing node so I can update its
properties?
You can use this to check existing datalist item.
var opportunity = orpList .childByNamePath(execution.getVariable("orpWorkflow_nodeName"));
// If the data list Item is not been created yet, create it
if (!opportunity ) {
var orpList = orpList .createNode(execution.getVariable("orpWorkflow_nodeName"),"dl:dataList");}
I have new inputs for a multidimensional array. The original inputs that are already defined are displayed correctly when called upon but the new inputs write as "undefined". I think it is recognizing the new inputs as variables. How do you get them to show up as a string?
var original = new Array(); //this is the array
function input(title, artist, ddate, genre, picsrc) {
this.Title = title;
this.Artist = artist;
this.Ddate = parseInt(parseFloat(ddate));
this.Genre = genre;
this.Picsrc = picsrc;
}
original[0] = {title:"Hope II", artist:"Gustav Klimt", ddate:1907, genre:"Art Nouveau", picsrc:"gustav.jpg"}; //and so on
Values that are added to the array are taken from a form.
function addit(form) {
G = form.Title.value //as a test
original[original.length++] = new input(form.Title.value, form.Artist.value, form.Ddate.value, form.Genre.value, form.Picsrc.value)
alert("your entry has been added")
alert(G) //value shows up in the alert
}
but when it is called back in this function:
$("#info").html(original[currentrecord]["title"]+"<br /><h2>"+original[currentrecord]["artist"]+"</h2>"+original[currentrecord]["ddate"]+"<br />"+original[currentrecord]["genre"]);
everything is being written as "undefined".
I am assuming that the data is successfully being added to the array, but maybe not in the right format?
I prefer using dot notation, but it's not a requirement.
The real issue is: JavaScript is case sensetive.
I would do it like this:
original[currentrecord].Title
original[currentrecord].Artist
and so on...
At one place in your code you are using all lowercase (when initializing original[0]), but in the constructor function you are using uppercase for the first letter.