Dejsa Cocan
Dejsa Cocan

Reputation: 1569

How to get another field value based on the raw value in a droplink field?

I'm working on a part of a sitecore site and I'm still getting used to how to code for it. I'm more familiar with using SQL to select, insert, delete, and update things, so I a probably making this issue much more difficult than it truly is.

Basically, what I have is a droplink field in the sitecore database called, "Complete Product Name." This is linked to another field called "Complete Name," which is the one I want to get the value for (So, I want to do a search for the "Complete Name" field using the "Complete Product Field" value).

 Item CPNItem = db.Items[orderItem.Fields["Complete Product Name"].Value];
 if (CPNItem != null)
 {

     //find complete name field on CPNItem

 }

I can get the "Complete Product Name" value just fine, but it's not what I want....I'm so used to using SQL to do searches like this that I'm really confused on how to proceed.

Any help would be great! :)

Upvotes: 1

Views: 1242

Answers (1)

Trayek
Trayek

Reputation: 4410

What you want to do is use something like the following:

Item CPNItem = db.GetItem(orderItem["Complete Product Name"]);
if (CPNItem != null)
{
    //find complete name field on CPNItem
    var name = CPNItem["Complete Name"];
}

Of course, that's assuming db is in fact an instance of the Sitecore.Data.Database. You don't have to use the .Fields["fieldname"].Value, as that could result in a NullReferenceException.

Upvotes: 7

Related Questions