1

I need to pass embedded field value as a parameter to the C# TBB. Could you please tell me what would be the syntax for the same. I am using below syntax , but it is not working

Component.fields.additinalInfo[0].fields.infoKey

Where additinalInfo is xml field of component, that is of type of embedded component containing fields infoKey and infoValue.

I am trying to pass field "infoKey" to the C# TBB.

2

It will nice if you provide more context to the question so that everybody understands the details and can provide your more appropriate answer.

Based on details in the question, the code to retrieve the value will be:

((ComponentLink)Component.fields["additinalInfo"]).value
  • I need to pass embedded component field value to the C# TBB to do any manipulation. I have created a C# TBB with parameter schema. parameter schema has a field Headertext of text type. Now “hedertext” that needs to be pass as a parameter , is not directly available on component instead it is field value of component that is embedded with main component. Now to pass embedded component field value to the C# TBB , I am using below code. Component.fields.additinalInfo[0].fields.infoKey But not able to retrieve the value of embedded field. It seems like the syntax is not correct. – Ritu Jun 11 '15 at 7:27
  • Did you try the code that I have given? Also, you can use debugger to debug your template code to find out the missing details. Refer to link: docs.sdl.com/LiveContent/content/en-US/… – Hiren Kaku Jun 11 '15 at 7:29
  • Issue is with parameter syntax that i am trying to pass to C# TBB. I am trying to pass field value of the embedded component that is embedded in main component. – Ritu Jun 11 '15 at 8:52
  • Hey I got the correct syntax for the same. Here it is Component.fields.additinalInfo.infoKey – Ritu Jun 11 '15 at 8:59
2

So if your parameter filed name is say "MyParameterField", you need to do below:

  1. Get the parameter text "Component.fields.additinalInfo[0].fields.infoKey" from the package.

    string parameterText= package.GetValue("MyParameterField");

  2. Get the value of the field

    string fieldValue = package.GetValue("parameterText");

The string "fieldValue" will contain the component field value needed.

If "Component.fields.additinalInfo[0].fields.infoKey" dosn't work, you can try "Component.fields.additinalInfo.values[0].fields.infoKey" as well. I havn't run the code but should work.

  • I have facing issue with the syntax only – Ritu Jun 11 '15 at 8:41
  • Component.fields.additinalInfo.values[0].fields.infoKey is not working. We need to figure out the syntax that will work for Embedded field value – Ritu Jun 11 '15 at 8:42
  • Hey I got the correct syntax for the same. Here it is Component.fields.additinalInfo.infoKey – Ritu Jun 11 '15 at 8:59
2

Actually, Component.fields.additinalInfo[0].fields.infoKey will not work because you are embed field do not have Fields class. Also, its not "fields", but "Fields". Try something like

Component.Fields.additinalInfo[0].infoKey

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.