Creating Dynamic URLs from list Contents

Hi,

Sorry to post so much. Very new to this and need all the help we can get.

I'm trying to change the contents of an Iframe based on selections from a cascading lookup fields.

But I keep getting [object Object] as the output.

function GetIframe() {
    var iframesite = "https://tenancy.sharepoint.com/sites/TEST-FAQS/";
    var iframepage = fd.field('ConfigItem').value;
    fd.field('IframeOutput').value = iframesite + iframepage;
}

The ConfigItem field is a lookup field in a SharePoint list and this code outputs: https://tenancy.sharepoint.com/sites/TEST-FAQS/[object Object]

How do I get it to take the actual value the ConfigItem field is currently set to?

Thanks in advance.

Hello @NG-Helpdesk,

This code fd.field('ConfigItem').value returns an object for Single Choice Lookup field.

If you need to return the selected element as a string, you need to use this code:

fd.field('ConfigItem').value.LookupValue;

You can find more information about how to manage Lookup field with JavaScript here.

1 Like

Hi @mnikitina,

THANKS! As always your help is invaluable!

Have a great day!!

1 Like

@mnikitina

Rather than creating a new thread I thought I would ask this here as it's related.

How do I refer to other values from my list once I have selected things from my cascading lookup?

What I have is this:

TicketType cascades to ConfigItem which cascades to SpesificItem and then I want to use the URL in the IframeLink column to set an Iframe in a HTML control and the IframeOnOff to control if that control is visible. But I can't find a way of referring to the value of the other columns properly.

Hello @NG-Helpdesk,

If you want to retrieve values of other fields from the list, you need to specify their internal names in the Lookup field Settings >> General >> Extra Fields. Just like you did to create Cascading dropdowns.

image

Then, you will be able to get the URL of the hyperlink field like this:

fd.field('Lookup').value.Hyperlink.Url

Where Hyperlink is the internal name of the field.

Hi @mnikitina,

Thanks for this. When I do this it breaks my form.

So I already have "TicketType/Id" in the Extra Field for the cascading lookup function. If I add "IFrameLink" the lookup stops working and the look up for that field populates with nothing:

I did that and then this:

fd.field('HLFileRead').value = fd.field('ConfigItem').value.IframeLink.Url;

I will want the cascading lookup to populate quite a few fields which will include URLs, Numbers and Text. Is there some documentation on what you change the end to depending on the field type?

Would they just be:

Hyperlink: fd.field('Lookup').value.InternalFieldName.Url;
Text: fd.field('Lookup').value.InternalFieldName.Test;
Number: fd.field('Lookup').value.InternalFieldName.Number;

Thanks very much for all your help.

Hello @NG-Helpdesk,

Do you get any errors in the browser console(F12)? Could you please share the screenshot.

There is no separate documentation for it, but the logic is pretty simple. If the field value is stored as an array of objects, you need to specify which object to return, e.g. URL of hyperlink field:
fd.field('Lookup').value.Hyperlink.Url

Single Line of Text field value is stored as a string, so you use this code:
fd.field('Lookup').value.FieldInternalName

You can find more information about getting field values in Managing SharePoint fields with JavaScript article.

Hi @mnikitina,

Thanks for this! Very helpful.

I solved it. It was my own silly fault. I was trying to get it to display a field that wasn't linked to the table I was using. I've fixed it now.

Sorry for asking so much, trying to do something quite complex with limited/very old Java scripting knowledge and your help has been invaluable, you should deserve a pay rise :smiley:

1 Like