Setting values in a cross-site lookup field with multiple values

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
MES5464
Posts: 94
Joined: Mon Aug 26, 2013

23 Jan 2014

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");

MES5464
Posts: 94
Joined: Mon Aug 26, 2013

23 Jan 2014

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'}]);

MES5464
Posts: 94
Joined: Mon Aug 26, 2013

23 Jan 2014

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.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests