problem in building schemas using code(SchemaBuilder API)

Posted by: bartek81 on 3 August 2017, 3:55 pm EST

  • Posted 3 August 2017, 3:55 pm EST

    Hello,<br>I try to  build a schema and save it to a file using SchemaBuilder API, dynamically, based on list of fields which i pass from the DB(list of columns in a view connected as a Relational Data Source). Every time number and names of the columns in a view can be different and I would like also to avoid using hard-coded names of attributes in web application (because they can change at any time in db), in other words, I can't do this as below (pseudocode):<br><br>
    if name_of_attribute(i)="Attr1" then<br>
    <br>
    AttributeBuilder Attr1 = new AttributeBuilder("Attr1");<br>
                Attr1.Caption = "Attr1";<br>
                Attr1.SetExpression<string>("=Fields!Attr1.Value");<br>
                Attr1.SetCaptionExpression<string>("=Fields!Attr1.Value");<br><br>
    elsif name_of_attribute(i)="Attr2" then<br><br>
    AttributeBuilder Attr2 = new AttributeBuilder("Attr2");<br>

                Attr2.Caption = "Attr2";<br>

                Attr2.SetExpression<string>("=Fields!Attr2.Value");<br>

                Attr2.SetCaptionExpression<string>("=Fields!Attr2.Value");<br>
    end if;<br>--------------------------<br>below I present what I try to do without a success:<br><br>Dim oSchema As New SchemaBuilder(schemaFileName)<br>Dim attribute As New ArrayList<br><br>name_of_attribute(i) - is a list of names of columns which i would like to be on the list of attributes<br>raport_caption(i) - is a list of names  to be captions for the above names<br><br>oSchema.AddDimension(New AttributesDimBuilder("Group_of_attributes"))<br><br>Dim attributeDimension As AttributesDimBuilder<br>        attributeDimension = oSchema.Dimensions("Group_of_attributes")<br><br>For i As Integer = 0 To number_of_attributes - 1<br><br>            attribute(i) = New AttributeBuilder(name_of_attribute(i))<br>            attribute(i).Caption = raport_caption(i)<br>            attribute(i).SetExpression(Of String)("=Fields!" & name_of_attribute(i) & ".Value")<br>            attribute(i).SetCaptionExpression(Of String)("=Fields!" & name_of_attribute(i) & ".Value")<br><br>            oSchema.AddDimension(New AttributesDimBuilder("Atrybuty").AddField(attribute(i)).SetDefaultField(attribute(i)))<br><br>            attributeDimension.AddField(attribute(i))<br>Next<br><br>oSchema.SaveSchema(schemaFile)<br><br>Dynamic schema generator is also not a solution for me because I would like to define attribute's properties on my own.<br><br>My question is what would be the right way to make it working as I described at the beginning? I would be thankful for any piece of code in VB as a solution for the above (I have to deal with a project written in VB and don't have much experience in writting the code in this language ;)<br><br>Thanks in advance for Your help.<br><br>Bartek<br>
  • Replied 3 August 2017, 3:55 pm EST

    Hello Bartek, <br><br>I would suggest you to use autogenerate schema method to generate schema. Later you can make use of the Schemabuilder API to modify it. Please take a look at this link which shows how to modify schema. <br><br>Feel free to reply. <br><br>Regards,<br>Aashish<br><br><br><br><br>
  • Replied 3 August 2017, 3:55 pm EST

    Hello,<br>I finally managed (today) to do what I meant, on my own. Thanks anyway for your reply :)<br>Solution was simple, just making a function returning AttributeBuilder (or MeasureBuilder) object based on given settings as a parameter and just pass it to attributeDimension.AddField (or measureDimension.AddField)<br><br>Regards,<br>Bartek<br>
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels