I have two lists in SharePoint, each with two columns:
List A
Column 1-----------Column 2
Bob-------------------Apple
Joe-------------------Orange
Jane------------------Banana
List B
Column 3-----------Column 4
Column 3 in List B is a lookup from Column 1 on List A, so there's a drop-down list of names in Column 3.
I would now like to set up Column 4 to auto-populate with the associated data in Column 2 from List A (i.e. if I select "Bob" in Column 3, Column 4 will populate "Apple". If I select "Joe" in Column 3, Column 4 will populate "Orange", and so on). I'm thinking this should be a calculated value but not sure.
Essentially, is it possible to set the value of a calculated column to data from another list? Or how else can I do this? Would it be a workflow, and if so, how? I'm working in SharePoint 2013, either just out of the box or I can do workflows. Thanks!
Similar requirement as this thread, so you could use JavaScript to populate Column 4 when Column 3 change in list new/edit form.
$(document).ready(function () {
var ID;
$('select[title= "Name"]').change(function () {
ID = $('select[title= "Name"] option:selected').val();
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Test",
CAMLViewFields: "<ViewFields><FieldRef Name='Country'/>, <FieldRef Name='Location'/>,<FieldRef Name='Mobile'/>,<FieldRef Name='Manager'/> </ViewFields>",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>" + ID + "</Value></Eq></Where></Query>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var Country = $(this).attr("ows_Country");
$('input[title="Country"]').val(Country);
$("input[Title='Country']").attr("disabled", "disabled");
var Location = $(this).attr("ows_Location");
$('input[title="Location"]').val(Location);
$("input[Title='Location']").attr("disabled", "disabled");
var Mobile = $(this).attr("ows_Mobile");
$('input[title="Mobile"]').val(Mobile);
$("input[Title='Mobile']").attr("disabled", "disabled");
var Manager = $(this).attr("ows_Manager");
Manager = Manager.replace(/[^a-z ;]/gi, '');
var re = /;;/gi;
var re1 = / /gi;
Manager1 = Manager.replace(re, ';');
Manager1 = Manager1.replace(re1, ', ');
Manager1 = Manager1.substring(1);
$('input[title="Manager"]').val(Manager1);
$("input[Title='Manager']").attr("disabled", "disabled");
});
}
});
});
});
Related
I am using searchData() to count rows under different conditions for display to the user, without affecting the table itself. Specifically one col is "available" and I want to show how many rows there are depending on the filter criteria set, for both available and unavailable states. Most filters are normal default type header filters.
To do this I use the dataFiltered() callback. Inside the callback I get all the filters in a list, then do a count with and without an "available" filter added to the list. The problem is that I have one column with a custom header filter, and Tabulator complains if this one is active when searchData() is called. The custom filter works as expected in the table. Relevant code snippets are:
//table def
dataFiltered:function(filters, rows) { SetCounts(filters, rows) },
// col def
{title:"Sex", field:"sex", visible:true, hozAlign:"center", headerSort:false,
headerFilter:true, headerFilterFunc:customSexFilter,
},
// custom filter
function customSexFilter(headerValue, rowValue, rowData, filterParams) {
return (headerValue == rowValue) || (headerValue == "M" && rowValue == "N") || (headerValue == "F" && rowValue == "S");
}
// dataFiltered callback (simplified; one of two cases shown)
var availFilter = { field: "avail", type: "like", value: "A"};
function SetCounts(filters, rows) {
if (!table) return;
var filt = table.getHeaderFilters().concat(filters.slice());
var nAll = rows.length;
var fA = filt.slice();
fA.push( availFilter );
var nAvail = table.searchData(fA).length;
\$("#rowCount").html([nAll, '/', nAvail, 'A'].join(''));
}
The error that I get is Filter Error - No such filter type found, ignoring: function o(o)
and the filter itself shows as
field: "sex"
type:o(o)
value: "F"
I've studied the docs but can't figure out what I'm doing wrong. Or is this not supported? Version 4.6.
#bknights posted an good answer to another question around populating a sublist in a suitelet.
However, my question follows on from that when using bk's code:
function getJoinedName(col) {
var join = col.getJoin();
return join ? col.getName() + '__' + join : col.getName();
}
searchResults[0].getAllColumns().forEach(function(col) {
sublist.addField(getJoinedName(col), 'text', col.getLabel());
nlapiLogExecution('DEBUG', 'Column Label', col.getLabel());
});
var resolvedJoins = searchResults.map(function(sr) {
var ret = {
id: sr.getId()
};
sr.getAllColumns().forEach(function(col) {
ret[getJoinedName(col)] = sr.getText(col) || sr.getValue(col);
});
return ret;
});
sublist.setLineItemValues(resolvedJoins);
The above works with a standard search with no formulae... How can we do this when I have multiple search columns which are formulae?
Using API1.0
In your search definition add a label to all formula columns. Then your column keys can be derived like:
function getJoinedName(col) {
if(col.getName().indexOf('formula') === 0 && col.getLabel()){
return 'lbl_'+ col.getLabel().toLowerCase();
}
var join = col.getJoin();
return join ? col.getName() + '__' + join : col.getName();
}
You can just get all the columns of the search result. columns = result[0].getColumns(). The reference the column where the formula column is. So if you look in the UI and it is the third from the top, you can get the value using result[0].getValue(columns[2])
This solution is dependent on the order of rows not changing.
Also if your saved search has labels for the Formulas, you can just use the labels as the field id.
I am trying to count comments or specific words written by users in Google Sheet table. for example 5 accounts have permission on sheet and i want to count how many comments or yes/no is written in table by each user. is there any solution for this task?
This will get the yes/no count case insensitive and it also has two arrays (yays and nays) which contain the row and column of each yes/no response. Also gets the Users email address.
function getYesAndNo()
{
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sht=ss.getActiveSheet();
var rng=sht.getDataRange();
var rngA=rng.getValues();
var yays=[];
var nays=[];
var yay=/yes/i;
var nay=/no/i;
var user = Session.getActiveUser().getEmail();
for(var i=0;i<rngA.length;i++)
{
for(var j=0;j<rngA[i].length;j++)
{
if(String(rngA[i][j]).match(yay))
{
yays.push([Number(i+1),Number(j+1)]); //rows and columns not indexes
}
if(String(rngA[i][j]).match(nay))
{
nays.push([Number(i+1),Number(j+1)]); //rows and columns not indexes
}
}
}
Logger.log(yays);
Logger.log(nays);
SpreadsheetApp.getUi().alert('User Email = ' + user + ' Yes Count = ' + yays.length + ' No Count = ' + nays.length);
}
I need to add multiple values (ID fields of another custom list) to a Multiple Lookup field using Sp-services.
What is the correct format of the data to be used ?
I have tried like ( 5,9,6 ) but only selecting the first item.
I am not quite sure why do you want to do this, because these items you will add - they can't be saved as values, because there is a relationship between the column and lookup list, i.e. if you have Lookup column to the List1 and you add a new value from the List2 with id 99 and save, it will save the reference to the list item with id 99 in the List1.
but if anything, it is possible, this is how I am appending multiple lookup selected values:
var lines = additionalTechnologies.split(';#');
$.each(lines, function (index) {
if (lines[index].length < 3) {
$("select[title='Additional Technologies selected values']:first").append("<option value=" + lines[index] + " title=" + lines[index + 1] + ">" + lines[index + 1] + "</option>");
$("select[title='Additional Technologies possible values'] option[value=" + lines[index] + "]").remove();
}
});
and remove them from the all items list. just do it vice versa.
I have found a way to do it.
// "list1Id" contains the array of LIST1 ID fields that you want to add...
// "MULTIPLELOOKUPFIELD" is the multiple lookup field in the LIST2...
var multipleLookupValue ="";
for(i = 0; i < list1Id.length ; i++)
{
multipleLookupValue = multipleLookupValue + list1Id[i]+";#data;#";
}
var method = "UpdateListItems";
$().SPServices({
operation: method,
async: false,
batchCmd: "New",
listName: "LIST2" ,
valuepairs: [["MULTIPLELOOKUPFIELD",multipleLookupValue]],
completefunc: function (xData, Status) {
//alert("Added new item to LIST2 list");
}
});
May be it will help someone...
I am developing one city filter in mongodb and nodejs with list of city with checkbox like this
city name 1
city name 2
city name 3
city name 4
once we click on any city or multiple city then we receive data with related to that city with following code.
var query = {city:{ $in:city }};
posts.find(query, {} , function(e,docs){
res.json(docs);
});
through query i just pass the city as array and receive Data..But my requirement is :
1.Suppose if i selected any 1 or 2 city then that city result come first and remaining city follow after that city even if those city not selected.
Thanks.
Query1 : db.city.find({name:{$in:["Bangalore"]}})
Query2 - db.city.find({name:{$nin:["Bangalore"]}})
**
- Edit
**
> var result = []; //Define an empty Array
> var cur = db.city.aggregate([{$match:{name:{$in:["Bangalore","Delhi"]}}}]); //Get matching city and save it in cursor
> while(cur.hasNext()){ result.push(cur.next()) } // Retrieve the cursor data and push it in array
> var cur = db.city.aggregate([{$match:{name:{$nin:["Bangalore","Delhi"]}}}]); // Get non matching city and save it in cursor (should be new variable)
> while(cur.hasNext()){ result.push(cur.next()) }
> for(var i=0;i<result.length;i++){printjson(result[i])}
This will give you expected result. Hope you are expecting the same :)