Add attributes and access them in scripting

Build 1501 on 14/Nov/2017  This topic last edited on: 5/Aug/2014, at 13:57

You can add custom attributes to schema, but only standard attributes can be accesses by means of basic commands.

Example: attributes Name and Id are the standard ones, thus you can query them a shown below:

    Dim objArticle = Ted.GetActiveArticle

    Dim artName = objArticle.Name

    Dim artId = objArticle.Id

Should you add to the schema an attribute such as "abc", the attempt to retrieve it as:

    Dim objArticle = Ted.GetActiveArticle

    Dim artAttr = objArticle.abc

will fail, as it is not a standard attribute.

For that purpose, you need to use a custom function, supplying the object ID and attribute name, such as

  Public Function GetObjAttrValue(ByVal objId As Integer, ByVal AttrName As String) As String

    If objId <= 0 Then Return ""

    Dim obj As IList(Of GenericAccessObj) = Editorial.EditorialLogin.GetLogin.GetAccessObjs(New Integer() {objId}, New ObjLoadDesc(New String() {AttrName}, Nothing))

    If Not obj Is Nothing Then

      Return obj(0).Obj.GetResolvedAttributeValue(AttrName)

    End If

    Return ""

  End Function

Alternatively, use this (example related to the extra attribute NumberOrd of an edition):

attrObj = UtilsBase.GetAttributes(Page.GetPageEditionId()) 'create a new IGenericAttrObj

Dim NumberOrd2 As String = attrObj.GetString("NumberOrd")