Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Get URL link from drop down document type field View modes: 
User avatar
Member
Member
Jon White - 12/18/2013 8:27:39 AM
   
Get URL link from drop down document type field
Hi,

I have two document types, one for staff (bio's) and one for projects.

I have a projects doc type with a field that uses a drop down option which is populated from the staff doc type 'name' field using an SQL Query.

i.e.

Project name
Staff member involved <-- make this linkable to their bio
Info about project

I can then get this field to show in my 'projects' preview transformation, and it works fine (like above).

The only problem I have is I want the user to be able to click this name and it go to the staff bio page.

using Eval("staffname") works but without the link, using DocumentUrl links to the project page. But i want it to link to the staff url address.

I hope that makes some sort of sense, i'm hoping it's just something i need to have in the transformation that tells it to get the opposing doc type link.

Thanks in advance
Jon


User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 12/18/2013 9:54:42 AM
   
RE:Get URL link from drop down document type field
Two options:

1). Create somewhat of a hard coded URL i.e. /Page/Staff/Eval("StaffName")
2). Create a method to get the URL based on the staff name. Do you have a staff ID or what control are you using in the Projects doc type to get the staff member involved? If you use a document selector, you will already have the URL but most likely not the "name" of the person unless your document name is the name of the person. If you use a user selector you'll have a userid but this is only useful if you have users for every person who has a bio.

Hope that helps

User avatar
Member
Member
Jon White - 12/19/2013 10:41:06 AM
   
RE:Get URL link from drop down document type field
Thanks, option 2 works well.

I'm using this transformation:

<a href="<%# GetDocumentUrl("StaffName","NodeAlias") %>"><%# Eval("StaffName") %></a>

This links well and redirects to the correct standard URL.

However when displayed on my project summary it shows:

Staff name: 57e96ad6-1a21-4561-8ffc-710c9d6b89f6 (which is the end part of the url redirect)

But I need it to show the staff name. You have mentioned this above.

How can I do this? Is this something to do with the site settings and how the url is displayed because the end of the url should say: /joebloggs

Thank you for your help

User avatar
Kentico Legend
Kentico Legend
Accepted solutionAccepted solution
Brenden Kehren - 12/19/2013 11:32:08 AM
   
RE:Get URL link from drop down document type field
In your transformation add this method:
<script runat="server">
protected string GetDocumentName(string docGuid)
{
string returnValue = "no name";
Guid guid = new Guid(docGuid);
if (guid != null || guid != Guid.NewGuid())
{
int nodeid = CMS.DocumentEngine.TreePathUtils.GetNodeIdByNodeGUID(guid, CMS.CMSHelper.CMSContext.CurrentSite.SiteName);
CMS.DocumentEngine.TreeNode node = CMS.CMSHelper.TreeHelper.SelectSingleNode(nodeid);
if (node != null)
{
returnValue = node.DocumentName;
}
}
return returnValue;
}
</script>
Then in your < a > tag use your method like this:
<a href="<%# GetDocumentUrl("StaffName","NodeAlias") %>"><%# GetDocumentName(EvalText("StaffName")) %></a>
I havn't tested any of this code but it should work.

User avatar
Member
Member
Jon White - 12/19/2013 4:36:36 PM
   
RE:Get URL link from drop down document type field
You're a genius!

Thank you so much! it worked!

I'm am very grateful for your help

User avatar
Member
Member
Jon White - 12/19/2013 5:24:10 PM
   
RE:Get URL link from drop down document type field
Hey FroggEye,

You've really helped me on this forum and I was wondering if you have a website or twitter I could follow? Not to pester you for technical help but you seem like you really know your stuff and thought you may be posting interesting stuff about Kentico somewhere?

If not no worries.

Thanks
Jon

User avatar
Kentico Legend
Kentico Legend
Accepted solutionAccepted solution
Brenden Kehren - 12/20/2013 9:23:17 AM
   
RE:Get URL link from drop down document type field
Thank you Jon! No website yet, been working on it for the last few years and just not enough time to spend on it because I've spent too much time working with clients.

You can follow me on twitter @bkehren

Best of luck!
Brenden