Forum Discussion

hkhan's avatar
hkhan
Ideator I
4 years ago
Solved

How can i create new permission and add that in

Hello,

How can i add new permission and add on add

I am using the following mode, it is creating permission but not adding it 

[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:b254bcb3-f5a7-4a5f-b41e-556278def9a4:type=text&text=Innovator%20inn%20%3D%20this.getInnovator%28%29%3B%0D%0Astring%20docid%20%3D%20this.getProperty%28%22id%22%2C%22%22%29%3B%0D%0AItem%20permissions%20%3D%20this.newItem%28%22Permission%22%2C%20%22add%22%29%3B%0D%0Apermissions.setProperty%28%22name%22%2C%20docid%29%3B%0D%0Apermissions%20%3D%20permissions.apply%28%29%3B%0D%0Athis.setProperty%28%22permission_id%22%2C%20permissions.getID%28%29%29%3B%20%20%20%0D%0A%09return%20this%3B]

  • Hi Haider

    I'm able to create permission and attach it to the item. Between which user account are you using ? I tried to use Super User and it is working but it will not work for the normal user as there is no access defined for the permission added. I added creator to the permission which is getting created and provided update access.

    Use below method (onBeforeAdd)

    Innovator inn = this.getInnovator();
    string docid = this.getID();
    Item permissions = this.newItem("Permission", "add");
    permissions.setProperty("name", docid);
    Item access = this.newItem("Access", "add");
    access.setProperty("can_get","1");
    access.setProperty("can_update","1");
    access.setProperty("can_discover","1");
    access.setProperty("can_change_access","1");
    access.setProperty("related_id","8FE5430B42014D94AE83246F299D9CC4");
    permissions.addRelationship(access);
    permissions.setProperty("name", docid);
    permissions = permissions.apply();
    this.setProperty("permission_id", permissions.getID());
    return this;

    Thanks

    Gopikrishnan R

6 Replies

    • haider's avatar
      haider
      Ideator I

      Onafteradd or onbeforeadd server events

      • Gopikrishnan's avatar
        Gopikrishnan
        Ideator I

        Hi Haider

        I'm able to create permission and attach it to the item. Between which user account are you using ? I tried to use Super User and it is working but it will not work for the normal user as there is no access defined for the permission added. I added creator to the permission which is getting created and provided update access.

        Use below method (onBeforeAdd)

        Innovator inn = this.getInnovator();
        string docid = this.getID();
        Item permissions = this.newItem("Permission", "add");
        permissions.setProperty("name", docid);
        Item access = this.newItem("Access", "add");
        access.setProperty("can_get","1");
        access.setProperty("can_update","1");
        access.setProperty("can_discover","1");
        access.setProperty("can_change_access","1");
        access.setProperty("related_id","8FE5430B42014D94AE83246F299D9CC4");
        permissions.addRelationship(access);
        permissions.setProperty("name", docid);
        permissions = permissions.apply();
        this.setProperty("permission_id", permissions.getID());
        return this;

        Thanks

        Gopikrishnan R