Clarity

 View Only
Expand all | Collapse all

Created by field needs to be updated

  • 1.  Created by field needs to be updated

    Posted May 11, 2021 10:42 AM
    Hello Everyone, 

    I have created the two sub object and copying the instance from one sub object to another sub object. Data is xogged successfully but it is coming as a XOG User. How can I copy the created by and place it ?

    Sub Object : 


    Copied data: 



  • 2.  RE: Created by field needs to be updated

    Posted May 12, 2021 06:19 AM
    Why not just have a new custom field to populate creator name from source ?


  • 3.  RE: Created by field needs to be updated

    Broadcom Employee
    Posted May 12, 2021 08:24 AM
    Hi Arunachalam,

    The system is displaying the "XOG, XOG" user as this is the account used when generating the session ID for your XOG calls.  It is possible to create a Session ID for another user without knowing credentials and using that to run the XOG calls.  This means that the user who created the original record would have the instance rights (as the instance creator) to the new instance and they must have create rights on your sub-object.

    Here is a GEL snippet to get a session ID for another user ID:

    <core:new className="com.niku.union.security.DefaultSecurityIdentifier" var="secId"/>
    <core:invokeStatic className="com.niku.union.security.UserSessionControllerFactory" method="getInstance" var="userSessionCtrl"/>
    <core:set value="${userSessionCtrl.init(Username, secId)}" var="secId"/>
    <core:set value="${secId.getSessionId()}" var="sessionID"/>
    ​

    Where Username is the username of the resource you want to appear in the Created By and sessionID is the resulting session ID you can use for your XOG call.  If you do not want the resource to have access to the new instances you are creating, you must either remove the instance rights for the resource or do as Nirbhay suggested and create a custom field.


  • 4.  RE: Created by field needs to be updated

    Posted May 12, 2021 08:35 AM
    Hi Ming, 

    Technically 'Yes' it is completely correct to create a new session ID  and use it to XOG; provided the User has XOG rights and Create rights on the object. But I see a conflict in putting someone's name as creator (by creating session) when originally they didn't do it in system. It just voids the logical purpose of the field. 

    Hi Arunachalam

    Ming's solution is correct and can be done easily with the snippet provided. My suggestion would be to just let it be and not override it, just use an admin account to create via XOG and have a custom field to populate resource name. 
    Again, upto your organization setup to decide.

    Thanks


  • 5.  RE: Created by field needs to be updated

    Posted May 12, 2021 01:24 PM

    My thinking is that the system should allow an easy option to enter the actual user who initiates the creation or update without any extra measures.

    That would make auditing, too, simpler.




  • 6.  RE: Created by field needs to be updated

    Posted May 18, 2021 01:32 PM
    Hello Nirbhay, 

    I like this Idea by creating custom field and update them when process is initiated. It worked. If I am manually entering the data without initiating the process, custom field will come as a blank. Any inputs or ideas ?


  • 7.  RE: Created by field needs to be updated

    Posted May 18, 2021 01:58 PM
    Hi Arunachalam

    Create a Boolean flag on the target object. When you are copying via process using XOG then set the boolean to True otherwise it would always be false.

    Have a process on the target object which would trigger on create, it should look for this boolean flag, if Flag=True then go to Finish. If Flag=False then set the custom_created_by same as created_by field value.

    --
    Nirbhay


  • 8.  RE: Created by field needs to be updated

    Posted May 18, 2021 02:02 PM
    One more thing, if you are creating the copy using Insert statements then the create process on Target Object will never get triggered which by default is fruitful for you. On manual creation process will trigger and set the custom_created_by value.


  • 9.  RE: Created by field needs to be updated

    Posted May 18, 2021 02:11 PM
    Hello Nirbhay, 

    I am NOT using insert statements. I am using the XOG IN methods. Is there a sample that you can suggest it will be helpful?


  • 10.  RE: Created by field needs to be updated

    Posted May 18, 2021 03:29 PM
    There is actually not much left for providing as a sample. This is the best I can provide.

    - You have to create a boolean field <your_flag_name> in the Target object
    - You already have a process which copies over data from source to target using XOG. Just add the boolean field as True in that XML
    - Create an Auto-start process on the Target object which triggers on create 
    - In the process do a decision check to find if <your_flag_name> is True or False. If True then put the process to completion and if False then run a script to either XOG <custom_created_by> or do SQL update to set it same as created_by.


  • 11.  RE: Created by field needs to be updated

    Posted May 19, 2021 08:08 AM
    Hello Ming,

    I am already using the concept that you mentioned but it is still doing the same. Please find the snippet of it and advise me. 

    <gel:parameter default="admin" var="xog_user"/>
    <gel:parameter default="1" var="debug"/>

    <!-- Define Data Source -->
    <gel:setDataSource dbId="Niku" var="dbSource"/>

    <!--get the xog session id and persist it for later use-->
    <core:catch var="xogLoginException">
    <core:new className="com.niku.union.security.DefaultSecurityIdentifier" var="secId"/>
    <core:invokeStatic className="com.niku.union.security.UserSessionControllerFactory" method="getInstance" var="userSessionCtrl"/>
    <core:set value="${userSessionCtrl.init(xog_user, secId)}" var="secId"/>
    <core:set value="${secId.getSessionId()}" var="xog_session_id"/>
    </core:catch>


  • 12.  RE: Created by field needs to be updated

    Posted May 19, 2021 08:17 AM
    I understand this question is meant for Ming but still answering : 

    <core:set value="${userSessionCtrl.init(xog_user, secId)}" var="secId"/>   -----> You are passing xog_user parameter which is set to 'admin' so it is going to have admin as the creator !!


  • 13.  RE: Created by field needs to be updated

    Posted May 19, 2021 08:44 AM
    Hello Nirbhay, 

    I still see in Ming's response Username is a variable. We have to define the variable name as Username right ?
    <core:set value="${userSessionCtrl.init(Username, secId)}" var="secId"/​



  • 14.  RE: Created by field needs to be updated

    Posted May 19, 2021 08:50 AM
    You will have to fetch the user name of the one initiating the process and then save it in that variable.

    <sql:query var="initBy" escapeText="0">
    select csu.user_name from bpm_run_processes brp
    join cmn_sec_users csu on csu.id=brp.initiated_by
    where brp.id=${gel_processInstanceId} 
    
    </sql:query>
    
    <core:set var="username" value="${initBy.rows[0].user_name}" />​



  • 15.  RE: Created by field needs to be updated

    Posted May 19, 2021 10:47 AM
    Thanks Nirbhay. This helped so that I dont need to create another process.