Announcement

Collapse
No announcement yet.

Global variables in BPM

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Global variables in BPM

    Hi, I had a BPM that worked great under V5.X. Over the New Year my SaaS instance has been upgraded to V6.0.8 and now that BPM has started to miss-behave.

    I have not looked hard yet, but I think it is something to do with global variables ($$variable) handling. Are there any known issues in this area or do I need to dig harder?

    Thanks

  • #2
    Hi Mat,

    Could be this change: Variables defined within Update Record actions won’t be passed back to the process. Use Execute Formula Script to define variables.

    2.15.0 Workflows: Send HTTP Request: Ability to take payload from a formula variable. Send HTTP Request: Increased max length of headers. Send HTTP Request: Fixed application/x-www-form-urlencoded payload. 2.14.1 Supporting custom entity types in Sync Target Lists with Reports. 2.14.


    Could you share your flowchart logic?



    Comment


    • #3
      That sounds like it could be the issue. That could impact a number of other big workflows too. Is this a temporary bug or a change made on purpose?

      Attached is an export of the process (in ZIP format) that I know to be the issue along with the screen shot of the layout. I have also included a screenshot of my (Sales Order Processing SOP) process which I will have to go through very carefully and completely re-test because of this. It is a lot of work.

      This is the process that I know has the issue and the CSV attached is the export of.:
      Click image for larger version

Name:	Screenshot.png
Views:	383
Size:	67.8 KB
ID:	65983

      SOP
      Click image for larger version

Name:	SOP1.png
Views:	343
Size:	54.3 KB
ID:	65985
      Click image for larger version

Name:	SOP2.png
Views:	389
Size:	27.5 KB
ID:	65986
      Attached Files

      Comment


      • #4
        It is this code snip that seems to be causing issues (last 6 lines). I am updating a "Lead" record from script. This really is the most obvious place to do it.
        Click image for larger version

Name:	Code Snip.png
Views:	319
Size:	36.2 KB
ID:	65989

        How else should I do this?

        I also note that this is find at the creation stage, it is just the update that fails.

        Comment


        • #5
          Hi Mat,
          As Yuri mentioned above you need to define somewhere before in the Execute Formula Script Task these variables with the `$` sign https://docs.espocrm.com/administrat...la/#variables:
          - contact_created
          - target_contact_id
          - account_created
          - target_account_id

          Basically, to fetch the ID from the Created Contact/Account/Opportunity Tasks you can with this formula https://docs.espocrm.com/administrat...ntityattribute.

          But I've noticed that in your flow might be the situations when you are not creating those entries. So in this way, I would use something like https://docs.espocrm.com/administrat...#recordfindone.

          Comment


          • #6
            Ok, I have done some digging and as far as I can see, this is not working correctly. Also note that this worked perfectly before the upgrade.

            Here is some of the process:
            Click image for larger version  Name:	Part Process.png Views:	0 Size:	40.8 KB ID:	66008

            If I look in "Define Constants & Globals" it has a lot of code, but this is the bit of interest:

            Code:
            // Globals that will be used
            $$account_created = 0;
            $$contact_created = 0;
            $$target_account_id = "ZZZ";
            $$target_contact_id = "ZZZ";
            $$short_name = "ZZZ"; // This value is checked for later
            $$productVendor = "ZZZ";
            I then jump to the "Create Account" box. This created the account (i.e. not updates) with "Create Related Record » Existing Account » Account » wcj85rrxng_gamrfgr1ja". This assigns a number of variables in the usual way and then includes the code:

            Code:
            // Set the Account Type
            type = $$account_type;
            
            // Store for later
            $$target_account_id = id;
            $$short_name = s4ShortName;
            $$account_created = 1;
            Note that:
            • We capture the id of the created account
            • We set the account_created flag for later

            Now moving on to the "Create Contact". This creates a contact (i.e. not updates) with "Create Related Record » Existing Contact » Contact » ouar2uosyp_hbz2j8m8px". This assigns a number of variables in the usual way and then includes the code:

            Code:
            // Status should be derived from the Lead Status
            status = $$contact_status;
            
            // Hook into the account that we have
            accountId = $$target_account_id;
            
            // Job Title
            title = bpm\targetEntity\attribute('title');
            
            // Capture the ID of the contact for later
            $$target_contact_id = id;
            
            // We created a contact so need to tie it back to the lead later
            $$contact_created = 1;
            And now to the issue ... when I open the Contact record it is linked to the Account "ZZZ" which is invalid. The account got created correctly but it seems the global $$target_account_id never gets assigned the new value.

            I also have other issues where globals are not being assigned values which I can show you. Interestingly I have some Updates that SEEM to be running code just fine.

            This is a really big issue for me because I rely on BPMs to drive things, and they are complicated.

            Thanks
            Last edited by MatLudlam; 01-05-2021, 06:45 PM.

            Comment


            • #7
              I have created a temp cloud instance and have a very simple job on there that shows one of the issues. Basically the global variable is not being updated.

              Happy to share login details to the temp instance at https://s4test.espocloud.eu/ or just help yourself if you can.

              I look forward to your feedback.

              Comment


              • #8
                Mat,
                When you are redefining a variable in a local Action (e.g. Create Opportunity (see screenshot)), the system redefines it locally in this action only. It doesn't redefine it globally.
                Attached Files

                Comment


                • #9
                  Hi Max, the release notes say "Variables defined within Update Record actions" this is not an update record, it is a create so should work.

                  I have a few issues:
                  1. The documented change makes no sense; it leads to inconsistent behaviour that will be really, really hard to track down and debug. Globals by definition are used to connect stages; those stages may run days apart. The BPM should fail, with an error, rather than do what it is, so that the issue can be found.
                  2. The documented change was to "Update Records", my example is "Create Record"
                  3. The documentation says "... defined within ..." I am not defining the global, I am changing the value of an already defined global
                  4. The impact of this is very hard for me to gauge on my existing workflows. I have a number of complex ones that rely on passing global variables around. I am sure other customers will be the same.
                  Max - how do I work around this?

                  Hi tarasm, I would really appreciate your feedback here.

                  Comment


                  • #10
                    Hi Mat,

                    If I'm not mistaken, we recommended to define $variables in Script Task. Update Record and Create Record action were not intended for any scripts execution, but only for setting record fields. Recently we refactored the logic so that variables defined within Update Record and Create Record won't be available out of the script. Changing of an existing variable won't work either. You can add an action Execute Formula Script within the same task and do all assignment there. Execute Formula Script is a new action type added recently.
                    Last edited by yuri; 01-06-2021, 01:21 PM.

                    Comment


                    • #11
                      Hi Mat,
                      Could you export and provide your BPM flowchart again. It seems that one you set to us is corrupted.
                      When I import it to my system I will see your logic, and probably will be able to provide you tips of how to make it works.

                      Comment


                      • #12
                        I have exported the process twice. Once (file 2) which doesn't export correctly because the description is not escaped correctly. I then copied the process, (file 3), removed the description and exported it again. Both are in the attached ZIP.

                        Can I ask you log a bug to escape the CR characters in the description when exporting a process.
                        Attached Files

                        Comment


                        • Maximus
                          Maximus commented
                          Editing a comment
                          Hi Mat,
                          Thanks for the attachment. Now we have holidays so I will check your issue on Monday and let you know.

                      • #13
                        tarasm I would really appreciate your feedback here.

                        Ok, I have solved the problem on this specific item, and looked through the rest of my BPMs for similar issues which I will resolve.

                        This brings up 2 points.

                        Changes like this to BPMs may make sense when discussed at the development stage but have broad impact on the business. I have spent many hours trying to track down and fix things that worked at the previous version. The documentation of the change was minimal an incorrect. This was not fixing a bug, it was a functionality change with significant impact to anyone using BPMs.

                        Secondly, I have a 2 feature requests that will make this and future changes easier.

                        1 - when a BPM fails at some point with an error, it shows on the specific Process diagram. There should be some way that you can make an error message available to the developer. Things like "Syntax error" or other errors.

                        2 - if someone tries to write to a variable that is going to get ignored, then it should stop the BPM with an error in that log. Whilst not ideal, this will help find and prevent these errors.

                        Comment

                        Working...
                        X