Request for Assistance in Implementing "Approved By" Field Functionality

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sapyantuk
    Senior Member
    • Oct 2020
    • 265

    Request for Assistance in Implementing "Approved By" Field Functionality

    Greetings, developers,
    I have implemented a new field called "Status," which includes options for both "Reject" and "Approve." To enhance this functionality, I am looking to introduce another field named "Approved By." This "Approved By" field should function similarly to the "Created By" or "Modified By" fields. While multiple users will possess the authority to either approve or reject, I am specifically interested in capturing and recording the user responsible for approving a transaction.
    My aim is to track and store the user who initiates the change of status to "Approve." Could you please guide me on how to achieve this?


  • victor
    Active Community Member
    • Aug 2022
    • 730

    #2
    If you enable the Audited option in the settings of this field, any changes to it will be made to the Stream. Does this functionality suit you?

    Click image for larger version

Name:	1.png
Views:	133
Size:	3.1 KB
ID:	96747

    Comment

    • sapyantuk
      Senior Member
      • Oct 2020
      • 265

      #3
      victor, No i need to Save this in Field.

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1250

        #4
        Hey sapyantuk

        You can create a relationship on your entityDefs, you can add the code below to your entity:

        PHP Code:
        {
            "fields": {
                "approvedBy": {
                    "type": "link",
                    "readOnly": true,
                    "view": "views/fields/user",
                    "fieldManagerParamList": []
                }
            },
        
            "links": {
                "approvedBy": {
                    "type": "belongsTo",
                    "entity": "User"
                }
            }
        } 
        
        Then you can use formula or Hooks to catch the person who changes the status field like below:

        PHP Code:
        if (entity\isAttributeChanged('status') && status == 'Approved') {
            entity\setAttribute('approvedById', modifiedById);
            entity\setAttribute('approvedByName', modifiedByName);
        }
        Hope this helps.
        Rabii
        Web Dev

        Comment

        Working...