Setting values in a cross-site lookup field with multiple values
When you query a cross-site lookup field in a list you get a return value something like this:
"32;#Atlanta;#54;#Denver"
To assign values to a cross-site lookup field you have to use something like this:
fd.field('CrossSiteLookup').control().value([{Id: 1, Title: 'Item 1'}, {Id: 2, Title: 'Item 2'}])
It would be nice if we could simply do something like this:
var str = "32;#Atlanta;#54;#Denver";
fd.field('CrossSiteLookup').control().value(str);
or
fd.field('CrossSiteLookup').control().value("32;#Atlanta;#54;#Denver");
"32;#Atlanta;#54;#Denver"
To assign values to a cross-site lookup field you have to use something like this:
fd.field('CrossSiteLookup').control().value([{Id: 1, Title: 'Item 1'}, {Id: 2, Title: 'Item 2'}])
It would be nice if we could simply do something like this:
var str = "32;#Atlanta;#54;#Denver";
fd.field('CrossSiteLookup').control().value(str);
or
fd.field('CrossSiteLookup').control().value("32;#Atlanta;#54;#Denver");
How does someone assign values to the cross-site lookup with multiple values like in my example?
I started by splitting the values into an array:
var vals = values.split(";#");
but I don't know how to turn that into a single command like:
fd.field('CrossSiteLookup').control().value([{Id: 1, Title: 'Item 1'}, {Id: 2, Title: 'Item 2'}]);
I started by splitting the values into an array:
var vals = values.split(";#");
but I don't know how to turn that into a single command like:
fd.field('CrossSiteLookup').control().value([{Id: 1, Title: 'Item 1'}, {Id: 2, Title: 'Item 2'}]);
Here is the code I got to work. I hope it is helpful to someone.
function populateDepots(depot, values)
{
var ary = [];
var vals = values.split(";#");
var i = 0;
while (i < vals.length)
{
var n = parseInt(vals);
i++;
var t = vals;
i++;
var obj = {Id: n, Title: t};
ary.push(obj);
}
fd.field(depot).control().value(ary);
}
If anyone wants to share a more elegant way to do this, please do.
function populateDepots(depot, values)
{
var ary = [];
var vals = values.split(";#");
var i = 0;
while (i < vals.length)
{
var n = parseInt(vals);
i++;
var t = vals;
i++;
var obj = {Id: n, Title: t};
ary.push(obj);
}
fd.field(depot).control().value(ary);
}
If anyone wants to share a more elegant way to do this, please do.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 23 guests