Solved

Lookup from Subsite O365


Badge +6

Hi everyone,

 

Currently I have a Helpdesk Jobs list and a Resources list (sites and contacts etc). These lists are on the same site /STW/Helpdesk.

From the Helpdesk form there is a Nintex look up field to sites on the resource list. With JavaScript 'client context', I populate certain fields on the form once this lookup changes:

- - - - - - - - - - - - - - - - - - - - - - -

code example:

NWF$(document).ready(function(){

var lookup = NWF$("#" + CallerLookUp); 

NWF$("#" + CallerLookUp).change(function(){     

var web = clientContext.get_web();        

var oList = clientContext.get_web().get_lists().getByTitle("Contacts");     

var listItem = oList.getItemById(this.value);        

clientContext.load(listItem, "Name", "EmailAddress");       

clientContext.executeQueryAsync(function(){

var CalNam = NWF$("#" + CallerName);

var CalNam = NWF$("#" + CallerEmail);

CalNam.val(listItem.get_item('Name'));

CalNam.val(listItem.get_item('EmailAddress'));

},

function(){ });   });  });

- - - - - - - - - - - - - - - - - - - - - - - -

 

After these fields populate and the form is saved I have a workflow that finds other information such as "Update current list item 'manager' where 'production area' value in the list 'area' matches the 'production area' value we've just put in our form via Javascript"

 

This all works perfectly well. However now I am required to create another Helpdesk. I've been asked to do it on a new site, as the current helpdesk site has many different list views and has enough navigation links down the left hand side as it is:

nav.png

Since building the subsite for the new helpdesk '/STW/Helpdesk/Tech' I cannot link to the resources lists like I could before. I can choose the site and list in the Nintex lookup field options and it does return me a list of sites to chose from, but my JavaScript does not do anything. Yet it all works fine on the other helpdesk located on the same page as the Resources. Surely though "/STW/Helpdesk" and "/STW/Helpdesk / Tech" are in the same site collection? Should my "client context" javascipt work for all sites in the same site collection?

 

I am considering duplicating the resources lists, so each helpdesk has their own resources (even though its the same data) but was wondering if anyone can help me set things up to only use one central resource data list, firstly for JavaScript "clientContext.executeQueryAsync" and additionally for cross-site workflow also.

 

Thank you,

Andrew

icon

Best answer by jackgelo 26 June 2015, 15:36

View original

3 replies

Userlevel 4
Badge +11

Hi,

I don't know if you have put the same javascript you have written before in the new subsite, but if you need to get data from a list in /STW/Helpdesk and you are in /STW/Helpdesk/Tech I think that you need to change some lines of code inside onChange function:

var siteUrl = '/STW/Helpdesk';

var clientContext = new SP.ClientContext(siteUrl);

and then start from your var web = clientContext.get_web();      

in this way you change the context of your calls to the web where the lists are located, if you don't specify a location for clientContext it will use the current web

Hope this help!

Giacomo

Badge +6

Hi Giacomo,

This is what I was looking for, I understand what you are saying and it makes sense.

I will try it as soon as I get a chance and I will be back to mark your answer correct if it works.

Thank you for your help.

Best Regards,

Andrew

Badge +6

Hi Giacomo and Emily,

I had tried the suggested action above at the start of the month without any success. I've since been drawn into working on other things but back on the project this morning I am still unable to look-up a list on a subsite.

I have duplicated the "Contacts" list so now it sits on the URLs '/STW/Helpdesk' and '/STW/Helpdesk/EMandI'

Within a list form on the site 'STW/Helpdesk' I have the code that looks up the "contacts" list also on 'STW/Helpdesk'. This ensures my code works, however when trying to inert the lines:

"var siteUrl = '/STW/Helpdesk/EMandI';

var clientContext = new SP.clientContext(siteUrl);"

The look up no longer works. the subsite EMandI has the latest updated Contacts list so I am aiming on looking up that contacts list.

I'm still going back and forth with this to see if I can get it working, but currently I've had no luck and have put in place duplicate lists (contacts) as a temporary measure.

Andrew

Reply