Where is the relationship for an embedded list called?

Patrick55
Giga Expert

So I understand that the refineQuery(current, parent) function within a relationship sets up a query that can be used to pull records for a embedded/related list.

Where exactly does this query actually get executed? .query() or .next()?

I'm struggling with an embedded list not updating with a field change on the form.

14 REPLIES 14

ricker
Tera Guru

I don't know of a manual process to reload embedded lists....ok so you are saving the record and refreshing but the related/embedded list is not changing? Are you sure the query and the list are correct before changing the field?  Can you provide specifics or screenshots? 

Unfortunately I'm not in a position where I can exactly provide full details otherwise I would.

But here are the critical lines of code

find_real_file.png

I've checked the obsIds list - it has the correct values in it

But I've also checked the results of querying "current" by doing:

current.query();
while (current.next()) {
    gs.info("TEST " + current.getValue('observable'));
}

after the addQuery() line, and that doesn't seem to have the correct results in it - only the first results that were added the first time the parent record was updated. I.e. it doesn't have everything that is correctly represented in obsIds.

Embedded lists only touch server side when loaded. So if one wants to make the embedded list react to changes on form, without submitting the form, client scripts are needed.

All lists of a form are stored on object GlideLists2. Properties of that object represent lists (embedded or related) - are ones of type GlideList2. One needs to loop through properties of GlideLists2 to find the needed embedded list and then it can be refreshed. The lookup is needed because embedded list will be represented by properties with a random GUID name - it will change on each reload of the form. So to refresh an embedded list one could write in a client script:

GlideLists2[getEmbeddedListGUID(GlideLists2)].refresh();

function getEmbeddedListGUID(gl2) {
	// find and return the proper name
}

One needs to keep in mind that refreshing the list will result in the mix of whatever is on the server overwritten by whatever has been edited on the form.

There are other methods to refresh an embedded list, like:

GlideLists2[getEmbeddedListGUID(GlideLists2)].setFilterAndRefresh('<encoded query>');

This can be confusing as the filter will be applied server side, so something that has been edited will be filtered in or filtered out in contradiction with the value on screen.

There are so many problems with this embedded list paradigm that I would really re-thing the refreshing thing 10 times before committing to doing it.

-O-
Kilo Patron
Kilo Patron

Or if you will:

Object.keys(GlideLists2)
	.filter(retainEmbeddedList())
	.filter(retainListOfTable('<table name>'))
	.map(refreshEmbeddedList())
	//.map(filterAndRefreshEmbeddedList('<encoded query>'))
	;

function filterAndRefreshEmbeddedList (filter) {
	return function (key) {
		GlideLists2[key].setFilterAndRefresh(filter);
		return key;
	};
}

function refreshEmbeddedList () {
	return function (key) {
		GlideLists2[key].setFilterAndRefresh('');
		return key;
	};
}

function retainEmbeddedList() {
	return function (key) {
		return GlideLists2[key].embedded;
	};
}

function retainListOfTable (tableName) {
	return function (key) {
		return GlideLists2[key].tableName == tableName;
	};
}

Thanks for your reply!

Trying to refresh the embedded list isn't actually exactly what I'm looking for - and definitely not without refreshing the page. My problem is that the embedded list is not displaying all the values in obsId, which I need.

My original question was addressing where this relationship script gets applied to try and debug how the query, set up with current.addQuery(), is actually used.

Thanks!