Routing form if opened in a dialogue

Hiya @Margo

Got a (hopefully quick one) I need to route my form if it is opened via a dialogue, directly from the form, but if the Invoice form is a dialouge and then my form is open from there, it doesn't route. This is my code

if (window.top.fd.control('Invoice_Items') || window[0].fd.control('Invoice_Items') || window[1].fd.control('Invoice_Items') || window[2].fd.control('Invoice_Items')) {
	return '81e81431-185e-42e8-b9df-a6a9337e3fb8'
}

Now I know this doesn't work because if the 1st check fails, the whole thing fails and it routes to the default form.

I have tried a try and catch, but this fails aswell...
try {
if (window.top.fd.control('Invoice_Items')) {
return '81e81431-185e-42e8-b9df-a6a9337e3fb8'
}
}catch (e){
if (window[0].fd.control('Invoice_Items')){
return '81e81431-185e-42e8-b9df-a6a9337e3fb8'
}
}

even though window[0].fd.control... has a value:
image

do you know how I can route the form is opened in a dialogue more than 1 window deep?

Thanking you in advance!

Hello @Jamal_Smith-Graham,

You can check if the form is opened in a dialog using this code:

    if (window.top !== window) {
       //form is opened in a dialog
    }

thanks @Margo but i need to know if it is being opened from a particular parent. And route based on that.

IE. I have 4 lists called clients, sales orders, invoices and line items.
If the line items form is opened from an invoice form I need a particlar version of line items to be displayed and a different version of the form if lines items is opened from a sales order form (this is the default form)
That works at the moment, but it breaks if a client form is opened, then the invoice form in a dialog then line items from the invoice form, it shows the default line items form intead of the one for the invoice.

So I need to check what the parent form is and route to the correct line item form.

Hopefully that makes sense?

@Jamal_Smith-Graham,

How do you open the form?

If you open a form using the direct link, you can pass Form Set ID in query parameter. Please find the code example here:

If you open a form from List or Library control, you can use the approach from this post:

1 Like

thanks @Margo it was from a list control, and the solution worked perfectly! :slight_smile:

1 Like