This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Create Dynamic Role for ITShop from Script

Hi all,

I'm trying to create a dynamic role fro the visbility of an ITShop from script triggered when a certain event is called but the script return me the following error:

"Dynamic roles: Write permission denied for value "Dynamic role"

 

This is my script:

 

' create or find dynamic group
Dim dynamicGroup As ISingleDbObject
Dim uid_dynamicGroup As String = Connection.GetSingleProperty("dynamicGroup","uid_dynamicGroup","ObjectKeyBaseTree='<Key><T>ITShopOrg</T><P>"+uid_customers+"</P></Key>'")
dynamicGroup = Connection.CreateSingle("dynamicGroup")
If (uid_dynamicGroup.Equals("")) Then

'msgbox ("uid_customers " + uid_customers)
dynamicGroup.PutValue("ObjectKeyBaseTree","<Key><T>ITShopOrg</T><P>"+uid_customers+"</P></Key>")
dynamicGroup.PutValue("uid_dialogschedule",connection.GetSingleProperty("dialogschedule","uid_dialogschedule","name = 'Dynamic roles check'"))
dynamicGroup.PutValue("uid_dialogtableobjectclass",connection.GetSingleProperty("dialogtable","uid_dialogtable","tablename = 'Person'"))
dynamicGroup.PutValue("whereclause","isnull(IsInActive, 0) = 0") 'only active employes
'dynamicGroup.PutValue("whereclause","1=2")
dynamicGroup.Save
dynamicGroup.Load
uid_dynamicGroup = dynamicGroup.getValue("uid_dynamicGroup")
...
dynamicGroup.PutValue("uid_dynamicGroup",uid_dynamicGroup)
dynamicGroup.Load

dynamicGroup.PutValue("whereclause","isnull(IsInActive, 0) = 0") 'only active employes
dynamicGroup.Save
dynamicGroup.Load

There is any way to accomplish that?

This script running on 7.0 didn't return any error now on 7.1 yes.

 

Thanks Michele

  • Hi Michele,

    you code sample looks a little bit shaky.

    You are creating a dynamic group, saving it. Loading the same dynamic group again, getting the uid of it, setting the uid of it, setting the where clause etc.

    Did you tried to debug your script in the System Debugger to identify what part of your code raises the error?

    I think the reason for the error message is, that you are trying to set the UID_DynamicGroup of an loaded dynamic group which is not allowed.

    Markus

  • The code above is an "extract" of the whole code I cut some parts to show only the relevant code (see ...).
    I discover that I have to fill the value DisplayName = "Dynamic role" of the table Dyanamic Group for not to return me an error.
    The good part is that this value is overwritten by the template custmoization with the value "Person in ..."
  • Glad you got it working.

    But I doubt that not setting the DisplayName was the cause of your issues. Just the workaround.

    The property DisplayName is and was a mandatory property in 7.1 and 7.0 and as you have already figured out, will be set by a template which is triggered when you set the columns UID_DialogTableObjectClass and ObjectKeyBaseTree which are mandatory as well.

    The only reasons i can imagine for your code to break when not setting the DisplayName is a customized value template for the column DynamicGroup.DisplayName or, as I have said before, setting the UID_DynamicGroup (PK) of an loaded dynamic group which is not allowed and would lead to the error you have seen.

    As suggestion for your sample code, i would use the method .FillPrimaryKey() for newly created iSingleDBObjects that allows you to access the primary key of the newly created object using GetValue without the need for saving it.

    Hth

    Markus

  • Something strange is happen, is my code:

    ' create or find dynamic group
    Dim dynamicGroup As ISingleDbObject
    Dim uid_dynamicGroup As String = Connection.GetSingleProperty("dynamicGroup","uid_dynamicGroup","ObjectKeyBaseTree='<Key><T>ITShopOrg</T><P>"+uid_customers+"</P></Key>'")
    dynamicGroup = Connection.CreateSingle("dynamicGroup")
    If (uid_dynamicGroup.Equals("")) Then

       dynamicGroup.PutValue("DysplayName","pippo") '<----- this the line I added

       dynamicGroup.PutValue("ObjectKeyBaseTree","<Key><T>ITShopOrg</T><P>"+uid_customers+"</P></Key>")
       dynamicGroup.PutValue("uid_dialogschedule",connection.GetSingleProperty("dialogschedule","uid_dialogschedule","name = 'Dynamic roles check'"))
       dynamicGroup.PutValue("uid_dialogtableobjectclass",connection.GetSingleProperty("dialogtable","uid_dialogtable","tablename = 'Person'"))
       dynamicGroup.PutValue("whereclause","isnull(IsInActive, 0) = 0") 'only active employes
       dynamicGroup.Save
       dynamicGroup.Load
       uid_dynamicGroup = dynamicGroup.getValue("uid_dynamicGroup")
    End If
    dynamicGroup.PutValue("uid_dynamicGroup",uid_dynamicGroup)
    dynamicGroup.Load
    dynamicGroup.PutValue("whereclause","isnull(IsInActive, 0) = 0") 'only active employes
    dynamicGroup.Save

     

    Now if I put the line dynamicGroup.PutValue("DysplayName","pippo") it returns me the error:

     Column DysplayName was not found in object of type DynamicGroup

    But there is that column in table DynamicGroup

    If I dont' put it returns me the error:

    Dynamic roles: Write permission denied for value "Dynamic role".

     

    I don't have customization on the column nor on the table

    I don't know what is happen

  • Are you sure, that column is named DysplayName?
    I would use DisplayName
  • You get the error Column DysplayName was not found in object of type DynamicGroup because the name of the column is DisplayName. You have a typo in your code.

    But even when you fix that, you will get the error Dynamic roles: Write permission denied for value "Dynamic role". because in your code line following the End If

    dynamicGroup.PutValue("uid_dynamicGroup",uid_dynamicGroup)

    you are trying to set the UID_DynamicGroup for an already loaded dynamic group object in the case that you have created it early in your If - code path.

  • Damn. You are right

     

    ' create or find dynamic group
    Dim dynamicGroup As ISingleDbObject
    uid_dynamicGroup = Connection.GetSingleProperty("dynamicGroup","uid_dynamicGroup","ObjectKeyBaseTree='<Key><T>ITShopOrg</T><P>"+uid_customers+"</P></Key>'")
    dynamicGroup = Connection.CreateSingle("dynamicGroup")
    If (uid_dynamicGroup.Equals("")) Then

    dynamicGroup.PutValue("ObjectKeyBaseTree","<Key><T>ITShopOrg</T><P>"+uid_customers+"</P></Key>")
    dynamicGroup.PutValue("uid_dialogschedule",connection.GetSingleProperty("dialogschedule","uid_dialogschedule","name = 'Dynamic roles check'"))
    dynamicGroup.PutValue("uid_dialogtableobjectclass",connection.GetSingleProperty("dialogtable","uid_dialogtable","tablename = 'Person'"))
    dynamicGroup.PutValue("whereclause","isnull(IsInActive, 0) = 0") 'only active employes
    dynamicGroup.Save
    dynamicGroup.Load
    uid_dynamicGroup = dynamicGroup.getValue("uid_dynamicGroup")
    Else
    dynamicGroup.PutValue("uid_dynamicGroup",uid_dynamicGroup)
    dynamicGroup.Load
    End If
    dynamicGroup.PutValue("whereclause","isnull(IsInActive, 0) = 0") 'only active employes
    dynamicGroup.Save
    dynamicGroup.Load

  • Just prepped your code sample using the new object layer from version 7 as exercise.

    You may find is useful as well as it demonstrates

    • Use of the ObjectKey class
    • Use of SQL Formatter
    • Use of Query objects
    • Use of Unit of Works
    • Use of TryGet

     

    Public Sub CCC_CreateOrUpdate_DynamicGroup(uid_customers As String)
        ' create or find dynamic group
        Dim dynamicGroup As IEntity = Nothing
        Dim f As ISqlFormatter = Session.SqlFormatter
        ' Create an ObjectKey for the customer node
        Dim ObjectKeyBaseTree As DbObjectKey = New DbObjectKey("ITShopOrg", uid_customers)
     
        ' Try to load the dynamic group frm the database
        If Session.Source.TryGet(
                Query.From("DynamicGroup") _
                .Where(f.Comparison("ObjectKeyBaseTree", ObjectKeyBaseTree.ToXmlString(), ValType.String, CompareOperator.Equal, FormatterOptions.NonUnicodeLiterals)) _
                .SelectNonLobs, dynamicGroup
        ) Then
            ' A dynamic group exists for our customer node
            ' Just change the where clause
            dynamicGroup.PutValue("whereclause""isnull(IsInActive, 0) = 0"'only active employes
        Else
            ' There is no dynamic group for our customer node
            ' Create a new dynamic group
            dynamicGroup = Session.Source.CreateNew("DynamicGroup")
            ' Set the values
            dynamicGroup.PutValue("ObjectKeyBaseTree", ObjectKeyBaseTree.ToXmlString())
            ' Optimization: UID_DialogSchedule for ootb schedules never change since version 7
            dynamicGroup.PutValue("UID_DialogSchedule""QER-B78E7C59F09D487085506ED339F0257D")
            ' Optimization: UID_DialogTable for ootb tables never change since version 7
            dynamicGroup.PutValue("UID_DialogTableObjectClass""QER-T-Person")
            dynamicGroup.PutValue("whereclause""isnull(IsInActive, 0) = 0"'only active employes
        End If
        ' Saving the changed or created dynamic group
        Using uow As IUnitOfWork = Session.StartUnitOfWork()
            uow.Put(dynamicGroup)
            uow.Commit()
        End Using
    End Sub

     

    Markus