Change form opened by Add "New Item" Link

Discussions about Cross-site Lookup
Locked
User avatar
TonyDuke
Posts: 71
Joined: Mon Sep 11, 2017

17 Oct 2017

Is there a way of changing the form that is opened when clicking the Add "New Item" Link, I want to open a New form from a specific form set not the default New form.
Depending on the form the Lookup is used in I may need to open different forms using the New Item button so this will need to be done within the parent form itself.

Thanks

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

17 Oct 2017

Hmm, what you can do here, is try to patch the URL of the Add "New Item" Link depending on your conditions. That should work.
Otherwise, it's a pretty complicated task.

Easier way might be to have multiple Source Lists for Related Items for different users. Then you can use workflow to copy all created items into one list. But I am not sure what your requirements are, this might not work for you.
Cheers

User avatar
TonyDuke
Posts: 71
Joined: Mon Sep 11, 2017

17 Oct 2017

Hi Nikita,

The link I wish to change is the link that appears under a Plumsail Lookup field if you tick the box Add "New Item" Link in the Cross Site Lookup settings, this won't generally be based on a condition within the form, its just that for our requirement we use different form sets for different content types.
In this particular scenario I have a new product Form with a Lookup to a Companies List filtered to only return items where Company Type = Supplier in that list, with the Add "New Item" Link displaying as "Add new Supplier". Currently this will take a user to the Default New Form for this list but we have created additional Form Sets with one specifically for Company Type = Supplier, and I would like to direct the user to this form instead of the default. In other locations within the site we use buttons to open these forms directly or for related items views we use versions of the code below.

Code: Select all

$("#idHomePageNewItem").attr("href", "http://site/list/newform.aspx?source=http://...........");
Could we use something similar to patch the URL of the Add "New Item" Link??

Thanks

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

17 Oct 2017

Try something like this. You'll need timer to wait while Cross-site Lookup initializes:

Code: Select all

function checkCrossSiteLink(){
	$link = fd.field('FIELD_NAME').control()._el().find('a:not(".select2-choice")');
	if ($link.attr("href")) {
		$link.attr("href", "YOUR_URL");
		clearInterval(timerId);
	}

}

var timerId = setInterval(function() {
  checkCrossSiteLink();
}, 500);
Cheers

User avatar
TonyDuke
Posts: 71
Joined: Mon Sep 11, 2017

18 Oct 2017

Hi Nikita,

I applied the above code and it works in a fashion, if I mouse over the link it shows the correct URL, if I right click and open in new tab/window the correct form opens however if I simply click on the link so the form opens in a dialog the form that opens is still the default new form for the List? Am I doing something wrong?

Code: Select all

function checkCrossSiteLink(){
	$link = fd.field('Manufacturer').control()._el().find('a:not(".select2-choice")');
	if ($link.attr("href")) {
		$link.attr("href", "https://**************.sharepoint.com/ERP/Lists/Companies/fd_Item_9bddd0c5-e97d-4b93-a5fb-9f0a742e0694_NewForm.aspx");
		clearInterval(timerId);
	}

}

var timerId = setInterval(function() {
  checkCrossSiteLink();
}, 500);
Thanks

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

18 Oct 2017

If this doesn't work, you can try changing default New Form for the Source List, adding this JavaScript to it. You won't need the previous code.

For example, something like this should redirect you to the correct Form:

Code: Select all

if (window != window.top && window.top.fd) {
  // the form is opened in a dialog from the parent form
  var parentType = window.top.fd.field("Type").value();
  if (parentType == "Supplier") {
    fd.openForm('fd_Item_72214b69-bec0-4ece-88e1-c8fdf854c601_NewForm.aspx');
  }
}
Just make sure that you open the form with Cross-site Lookup in regular mode, not in dialog, and that you can somehow check the type you are looking for ("Supplier"). You just need some way to check that the form has been opened from the Cross-site Lookup, here I did it with an extra field "Type" located on the same form as the Cross-site Lookup.
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests