Add New Item Button - List or Library Control

Hi Guys,

We have a Form with a List or Library Control where we need to Pass data through from the parent to the child when a user clicks the Add New Item. For now I have done this by creating a button on the form and placing this above the control, this works really well. My code in the button OnClick is:

openDialog();

function openDialog () {
debugger;
var itemId = fd.itemId;
var costUplift = fd.field('Cost_x0020_Uplift_x0020__x0025_').value;
var profitMultiplier = fd.field('Profit_x0020_Multiplier').value;
var status = fd.field('Status').value;
Dialog.open("https://wrssolutionscom.sharepoint.com/ERP/_layouts/15/listform.aspx?PageType=8&ListId=%7B1D5BE483-D200-46DB-975B-ED444BCFAC5E%7D", { 
	quotationReferenceId: itemId,
	costUplift: costUplift,
	profitMultiplier: profitMultiplier,
	status: status
});
}

My questions are: -

a) Could we lose the additional button and inject this functionality into the standard Add new item button on the List or Library Control?
b) Can we hide the default Add new Item button from the control without making the whole control Read Only?

I assume both of the above are possible, it would be good to know how to do both as in this scenario I will probably stick with the additional button and hide the default but in others it may be easier to use the default but we would still want to pass through field data…

Also how to hide other functions within the List or Library control such as the delete item button?

Thanks

Dear Tony,

You don’t need to pass the data from the parent to the child because on the child form you still have access to the parent form by “window.top.fd”.

You can hide delete and edit columns by this code:

fd.control("SPDataTable0").widget.hideColumn("#delete");
fd.control("SPDataTable0").widget.hideColumn("#edit");

To hide a default “Add new item” button:

$(fd.control("SPDataTable0").$el).find('.btn').hide()

Hi Alex,

I have tried to use the window.top.fd functionality and it doesn’t work as I’d expect, could you let me know where I’m going wrong please??

var status = window.top.fd.field('Status').value;
console.log(status);

The Error I get is: -

VM587 spform.js:1 TypeError: Cannot read property 'field' of undefined
at eval (eval at e._executeCustomJavaScript (spform.js:38), <anonymous>:39:29)
at spform.js:1
at Array.map (<anonymous>)
at Function.e.safeRun (spform.js:1)
at spform.js:68

Thanks

Dear Tony,

Have you placed the “window.top.fd” code on the child form? Do not forget to check if window.top.fd is defined because it’s only defined when a child form is opened in the dialog mode.

Hi Alex,

The code is 100% on the child form and it doesn't matter if open a form in a dialog by clicking the Add new item button on a List or Library Control, or click the edit button next to an item, or click the new button that I added to open a New form in a dialog the result is the same...

This is my code I'm testing with: -

// Set Variables for values from Arguments
setStatusFromTopWindow();

function setStatusFromTopWindow () {
	debugger;
	if (window.top.fd) {
		var status = window.top.fd.field('Status').value;
	} else {
		var status = 'In Progress';
	}
}

My Form looks like: -

And the debug: - Capture

Thanks

Dear Tony,

I’m sorry, I forgot to mention you that you need to define fd globally in the parent form: window.fd = fd;

Hi Alex,

Thats worked well thank you…