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,
    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):


    if name_of_attribute(i)="Attr1" then



    AttributeBuilder Attr1 = new AttributeBuilder("Attr1");

                Attr1.Caption = "Attr1";

                Attr1.SetExpression("=Fields!Attr1.Value");

                Attr1.SetCaptionExpression("=Fields!Attr1.Value");


    elsif name_of_attribute(i)="Attr2" then


    AttributeBuilder Attr2 = new AttributeBuilder("Attr2");


                Attr2.Caption = "Attr2";


                Attr2.SetExpression("=Fields!Attr2.Value");


                Attr2.SetCaptionExpression("=Fields!Attr2.Value");

    end if;
    --------------------------
    below I present what I try to do without a success:

    Dim oSchema As New SchemaBuilder(schemaFileName)
    Dim attribute As New ArrayList

    name_of_attribute(i) - is a list of names of columns which i would like to be on the list of attributes
    raport_caption(i) - is a list of names  to be captions for the above names

    oSchema.AddDimension(New AttributesDimBuilder("Group_of_attributes"))

    Dim attributeDimension As AttributesDimBuilder
            attributeDimension = oSchema.Dimensions("Group_of_attributes")

    For i As Integer = 0 To number_of_attributes - 1

                attribute(i) = New AttributeBuilder(name_of_attribute(i))
                attribute(i).Caption = raport_caption(i)
                attribute(i).SetExpression(Of String)("=Fields!" & name_of_attribute(i) & ".Value")
                attribute(i).SetCaptionExpression(Of String)("=Fields!" & name_of_attribute(i) & ".Value")

                oSchema.AddDimension(New AttributesDimBuilder("Atrybuty").AddField(attribute(i)).SetDefaultField(attribute(i)))

                attributeDimension.AddField(attribute(i))
    Next

    oSchema.SaveSchema(schemaFile)

    Dynamic schema generator is also not a solution for me because I would like to define attribute's properties on my own.

    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 ;)

    Thanks in advance for Your help.

    Bartek
  • Replied 3 August 2017, 3:55 pm EST

    Hello Bartek,

    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.

    Feel free to reply.

    Regards,
    Aashish




  • Replied 3 August 2017, 3:55 pm EST

    Hello,
    I finally managed (today) to do what I meant, on my own. Thanks anyway for your reply :)
    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)

    Regards,
    Bartek
Need extra support?

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

Learn More

Forum Channels