Looping/Counting items in Related Items

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
joss.wilde
Posts: 18
Joined: Wed May 17, 2017

05 Jul 2017

Sadly I had to delete and recreate that list along with the forms from a backup I created due to being unable to get the original form/list working properly. I will however see if the issue reoccurs once I have got back to where I was as it is using the same code as before. Shall let you know soon as I can but thank you again.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

05 Jul 2017

No problem, keep us updated. We would love to know if it resolved the issue and if not, we'll definitely get to the bottom of it.
Cheers

joss.wilde
Posts: 18
Joined: Wed May 17, 2017

05 Jul 2017

OK - I have recreated how it was before and still experiencing the same issue when it comes to counting/looping through relatedItems list. Also it will not load the form correctly in IE or Edge but does still in Firefox for some reason.
IE errors.PNG
IE errors.PNG (43.67 KiB) Viewed 2110 times
In Form Designer looks like:
fd.PNG
fd.PNG (52.75 KiB) Viewed 2110 times
Let me know if you need any more information though.

Thanks again,
Joss.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

05 Jul 2017

Code: Select all

SCRIPT1004: Expected ';'
fd_Item_NewForm.aspx (616, 7)
This error in your IE console log indicates a missing ";" in the code. It might be the reason why the code doesn't work as intended.

Click on the error in your browser console and try to find the exact place where the missing semicolon should be.
Cheers

joss.wilde
Posts: 18
Joined: Wed May 17, 2017

05 Jul 2017

I did wonder this too and had a look, however why then would it work in Firefox I wonder?
It is pointing to the first line of a function, which shouldn't have a ; as you can see below:

Code: Select all

async function initForm() {
	try { var results = await getPON(); }
	catch(e) { console.log(JSON.stringify(e)); }
	var tmp; var pon = 0;
	
	if (results) {
		for (i in results) {
			tmp = parseInt(results[i].Title.match(/\d+/)[0],[10]);
			if (tmp > pon) { pon = tmp; }
		}
		pon += 1;
		pon = 'TD' + pon;
		console.log('PO: ' + pon);
		fd.field('Title').value(pon);
		
		fd.populateFieldsInGrid($('.related-items'), {
				Title: pon,
		});
		
		cleanUp(false); //Fn to remove any related items to the PON.
	} 
	else { alert('Unable to get results.'); }
}
and in IE Debugger:
code missing.PNG
code missing.PNG (14.19 KiB) Viewed 2105 times
I can't see any missing ; there...unless it's an issue with IE/Edge and async functions...

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

06 Jul 2017

Yes, the error you are getting is caused by async and await, as these are not supported in IE.
IE await and async.jpg
IE await and async.jpg (47.76 KiB) Viewed 2101 times
While I can't say for sure what exactly causes duplication of values from the list when looping, it's most likely due to some custom code elements. If you can, I would like to ask you to comment out all your code - JS and CSS, and try to test looping without it.

In any case that should allow us to pinpoint the root of the problem.
Cheers

joss.wilde
Posts: 18
Joined: Wed May 17, 2017

06 Jul 2017

Sadly it seems quite correct that await/async functions dont work in IE or Edge, will have to rewrite code for that a bit. However on to the issue at hand, as you asked I have commented out all of the code except what you see below:
code1.PNG
code1.PNG (20.28 KiB) Viewed 2098 times
code2.PNG
code2.PNG (27.77 KiB) Viewed 2098 times
Then testing in Edge (the form now works of course) but strangely still seeing the same loop and counting issue...unless it's a problem with the sharepoint list itself ^
loop no code.PNG
loop no code.PNG (29.43 KiB) Viewed 2098 times

joss.wilde
Posts: 18
Joined: Wed May 17, 2017

06 Jul 2017

Decided to do some more testing however, this time on the edit form, which has the relatedItems list already with items in it. When running the loop without making any changes it's fine:
editloop.PNG
editloop.PNG (17.5 KiB) Viewed 2097 times
However, if I an add an item it will count the new item twice but not the existing items:
editloop2.PNG
editloop2.PNG (21.96 KiB) Viewed 2097 times

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

06 Jul 2017

Joss, if at all possible, can you test this on a different site, without the workflow and other elements already created? If it's not the code, it must be something else and I have no idea what it might be. This truly is a bizarre case, for we cannot find any reason why it would appear this way. Maybe on a fresh site with very simplistic lists, you might escape it, if only for testing purpose. If not, we'll have to look even further.

On our part, we didn't manage to get anything similar in all our tests. We'll keep looking, but we also want to get as much feedback from you as possible to determine the reason of this strange behavior.
Cheers

joss.wilde
Posts: 18
Joined: Wed May 17, 2017

07 Jul 2017

I don't think we have another Sharepoint site to test it on sadly, however there is no longer a workflow on this list since I had to recreate this list from that earlier problem.

Is it worth me sending you the code/form to try on a site/list you have? Would just would need to change a couple of the REST queries in there is all.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests