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 

Innovator inn = this.getInnovator();
string docid = this.getProperty("id","");
Item permissions = this.newItem("Permission", "add");
permissions.setProperty("name", docid);
permissions = permissions.apply();
this.setProperty("permission_id", permissions.getID());   
	return this;

Parents Reply Children
  • 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

  • Hello Gopikrishnan

    I am trying to run this method on the lifecycle transition but this does create a permission but not the link to the document, any idea why? 

  • Hi hkhan

    For life cycle method, use below method in Post Event of life cycle transition

    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.setAction("edit");
    this.setProperty("permission_id", permissions.getID());
    this.setAttribute("version", "0");
    Item result = this.apply();
    return this;

    Thank You

    Gopikrishnan R