Workflow rule is not being triggered after custom code execution

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • a.slyzhko
    Member
    • Oct 2023
    • 90

    Workflow rule is not being triggered after custom code execution

    Hi!
    Let me explain my situation. I have created custom detail view for Task entity. I added button to this view, which opens modal dialog. In this modal dialog user selects assignedUser and enother entity jobInstruction, which is related to selected user. When user clicks 'Done', I user Espo.Ajax.postRequest method to relate selected entites. After that, detail view is rerendered and I see, that selected entites are updated, but my workflow rule afterUpdate assignedUser is not triggered. What am I missing in my code?
    Here is modal dialog code before close:
    PHP Code:
    actionSave: function () {
    // some code to get entities ids
    
    (async () => {
    const [assignedUserResponse, jobInstructionResponse] = await Promise.all([
    Espo.Ajax.postRequest('Task/' + this.options.taskId + '/assignedUser', {
    id: userId
    }),
    Espo.Ajax.postRequest('Task/' + this.options.taskId + '/jobInstruction', {
    id: jobInstructionId
    })
    ]);
    if (assignedUserResponse && jobInstructionResponse) {
    Espo.Ui.success(this.translate('Done'));
    } else {
    Espo.Ui.error(this.translate('Error'));
    }
    this.trigger('done', 'view is closed');
    this.close();
    })();​
    ​} 
    




    And here is how I catch done event on parent view:

    PHP Code:
    actionAssignExecutorButtonClick: function () {
    this.createView('dialog', 'custom:views/modals/assign-executor-dialog', {
    teamId: this.model.get('teamsIds')[0],
    taskId: this.model.get('id')
    }, view => {
    view.render();
    this.listenToOnce(view, 'done', response => {
    this.model.fetch();
    this.reRender();
    });
    });
    },
    Last edited by a.slyzhko; 10-26-2023, 10:59 AM.
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    Better do it the following way:

    PHP Code:
    this.getModelFactory().create('Task')
        .then(task => {
            task.id = this.options.taskId;
    
            return task.save({assignedUserId: userId}, {patch: true});
        }); 
    
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment


    • a.slyzhko
      a.slyzhko commented
      Editing a comment
      Thanks a lot! Your approach helped me
  • a.slyzhko
    Member
    • Oct 2023
    • 90

    #3
    One more question. I want to set as many as possible fields as read-only. When I set assignedUser as read-only, this approach doesn't relate selected entities. What can I do in this case?

    Comment

    • yuri
      Member
      • Mar 2014
      • 8440

      #4
      As of v8.1 it won't be possible to link/unlink belongsTo and hasOne relationships. Only via Create and Update record operations.

      I'm not sure whether I understood you right. There's the ability to set a link as readOnly in metadata > entityAcl. https://docs.espocrm.com/development...ta/entity-acl/
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1250

        #5
        what is the difference between setting a field readOnly in entityDefs vs entityAcl.

        In past i have used readOnly on entityDefs but issue is that these fields can't be set/updated by frond-end (was i missing something here). if i have a field (bool) Active and want to set this field as readOnly by all users including admins but also i want to be able to change the state of this field from front-end (custom view) would do be possible or do i have to do it in back end ?​
        Rabii
        Web Dev

        Comment


        • yuri
          yuri commented
          Editing a comment
          Use entityAcl to restrict access to fields that should not be able to be undone in the Entity Manager. But this topic is about relationships, not fields. Better to create a separate topics for separate questions.

        • rabii
          rabii commented
          Editing a comment
          Thank you.
      • rabii
        Active Community Member
        • Jun 2016
        • 1250

        #6
        Originally posted by a.slyzhko
        One more question. I want to set as many as possible fields as read-only. When I set assignedUser as read-only, this approach doesn't relate selected entities. What can I do in this case?
        AFAK when a field / link is set as readOnly then it can not be updated by front end, i have same problem in past i end up setting those field invisible when empty and only after i update the set from front end i apply readOnly afterwards. Not sure if there is a way or i am missing but i have looked into code base to find similar use case but didn't.
        Rabii
        Web Dev

        Comment

        • a.slyzhko
          Member
          • Oct 2023
          • 90

          #7
          Originally posted by yuri
          As of v8.1 it won't be possible to link/unlink belongsTo and hasOne relationships. Only via Create and Update record operations.

          I'm not sure whether I understood you right. There's the ability to set a link as readOnly in metadata > entityAcl. https://docs.espocrm.com/development...ta/entity-acl/
          Thanks. I tried adding this logic to the entityAcl of the Task entity, and it worked. I applied "nonAdminReadOnly": true to my relations and fields. Now, non-admin users can't edit the relation in the detail view, which is exactly what I want. However, there's another small issue. Is there any parameter that can be used alongside nonAdminReadOnly to disable inline editing and prevent users from editing this relation when they click on the "Edit" button? Currently, for regular users, it appears as if they can edit this field/relation, but when they save changes, the changes are immediately reverted. Additionally, I found a bug/feature where, if a user tries to edit a field/relation that is marked as readOnly/nonAdminReadOnly in entityAcl and then saves the changes, the changes are reverted. However, the 'modifiedBy' field displays that the entity was modified by the current user, even though no changes were applied

          Comment

          • yuri
            Member
            • Mar 2014
            • 8440

            #8
            Administration > Entity Manager > {Entity} > Fields > {field} > Read-only.

            Or manually, in metadata > entityDefs > {Entity} > fields > {field} > readOnly.
            If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

            Comment


            • yuri
              yuri commented
              Editing a comment
              This will apply for all users. If you want only for non-admin users, you can use Roles with field level security.
          Working...