Referencing a field in parent record when creating new linked record

I am trying to create a task with an action button on the opportunities module, i want the subject of the new related task to be a concat of some fixed text and a value from the parent opportunity the button is being clicked on. The button works in creating the task but only the prefilled text is added to the subject, my attempt to pull the field value from the opportunity is always blank. Current calculation is: 

concat(string("Test Statement-"),string(related($opportunities, "pr_quotewerks_id")))

Does anyone have any advice, i feel like it isn't possible as this isn't the first time i've tried however i hope i am wrong. It doesn't seem like a very "outside the box" idea.

Thanks All

Parents
  • Hello  ,

    The formula that you are using is correct, when placing a similar one in a calculated field the Related record does render as expected: 

    https://www.screencast.com/t/nxlReRCVv

    Investigating open issues I did come across the following pertaining Action Buttons that believe is similar:

    #90036 ( portal.sugarondemand.com/90036 )



    My recommendation for you would be to create a case for our support team to make sure it's the same to make sure that you are posted on the issue resolution process. 


    While this is not fixed, I though about a workaround.
    The only thing that crosses my mind is the following:  



    1 - Create a checkbox field on the Tasks module to indicate Tasks that are being created by your Action Button. 

    The field doesn't need to be shown to the users, make sure you set it to Selected in the Action Button Settings: 

    2- After having that you can use a SetValue Dependency to populate the Subject of the Task with your formula when the checkbox is checked. 

    It Tried something like this and it works:

    <?php
    
    //path custom/Extension/modules/Tasks/Ext/Dependencies/task_created_action_button.php
    
    $dependencies['Tasks']['created_action_button'] = array(
        'hooks' => array("edit", "view"), //not including save so that the value isn't stored in the DB
        'trigger' => 'equal($created_action_button_c,true)',
        'onload' => true, //Whether or not to trigger the dependencies when the page is loaded
        'actions' => array(
            array(
                'name' => 'SetValue',
                'params' => array(
                    'target' => 'name',
                    'value' => 'concat(string("Test Statement-"),related($opportunities,"description"))'
    
                )
            )
        )
    );



    Just make sure to adapt the field names to the ones on your instance. 

    Let me know if this works for you. 

    Cheers, 

    André 

Reply
  • Hello  ,

    The formula that you are using is correct, when placing a similar one in a calculated field the Related record does render as expected: 

    https://www.screencast.com/t/nxlReRCVv

    Investigating open issues I did come across the following pertaining Action Buttons that believe is similar:

    #90036 ( portal.sugarondemand.com/90036 )



    My recommendation for you would be to create a case for our support team to make sure it's the same to make sure that you are posted on the issue resolution process. 


    While this is not fixed, I though about a workaround.
    The only thing that crosses my mind is the following:  



    1 - Create a checkbox field on the Tasks module to indicate Tasks that are being created by your Action Button. 

    The field doesn't need to be shown to the users, make sure you set it to Selected in the Action Button Settings: 

    2- After having that you can use a SetValue Dependency to populate the Subject of the Task with your formula when the checkbox is checked. 

    It Tried something like this and it works:

    <?php
    
    //path custom/Extension/modules/Tasks/Ext/Dependencies/task_created_action_button.php
    
    $dependencies['Tasks']['created_action_button'] = array(
        'hooks' => array("edit", "view"), //not including save so that the value isn't stored in the DB
        'trigger' => 'equal($created_action_button_c,true)',
        'onload' => true, //Whether or not to trigger the dependencies when the page is loaded
        'actions' => array(
            array(
                'name' => 'SetValue',
                'params' => array(
                    'target' => 'name',
                    'value' => 'concat(string("Test Statement-"),related($opportunities,"description"))'
    
                )
            )
        )
    );



    Just make sure to adapt the field names to the ones on your instance. 

    Let me know if this works for you. 

    Cheers, 

    André 

Children
  • Hi Andre,

    Thanks very much for the help there, i am unfortunately going to have to adapt your work around as i do not have the level of access to work on the code like you provided. Instead i will follow the same idea and use a process definition to combine the two pieces of text and then clear the checkbox and helper text field. It is a pain but have set it up and works exactly as intended. Thanks for the inspiration!