Calculated fields - get value from a field within the same module

Hi all,

Here's what I'd like to achieve.

We have a custom module (called Opportunities) in which we can attach documents (contracts). There's is a tab called "Contracts" within that module.

Within that "Contracts" tab, we have several fields but only two of them are concerned by my request.

1st field = Contract attachment

2nd field = Contract number

Our contracts are named this way: "yyyy-mm - specific internal number - name of client"

When I upload a contract to the Documents module, the name is correctly matched = "yyyy-mm - specific internal number - name of client.pdf"

I can easily attach a contract from the Documents module to the "Contracts" tab. However, the name of the contract, basically the name of the document, already contains the contract number. The part where you have "yyyy-mm - specific internal number"

I'd like the "Contract number" field to automatically grab either the entire "Contract attachment" name or if possible, grab the first part of the name. This way, I would only have to attach my contract and BAM, the "Contract Number" field would be auto-populated. I have like 200+ contracts to attach and if I need to copy/paste the name each time, that will take me ages!

I tried calculated fields without any luck so far.

Any idea or suggestions?

Thanks all for your help!

  • Hello Cedric,

    To copy the value of a field in the same module you would set the Formula to be '$' and then the field name.  For example, if I wanted to copy the value of the Name field in a module into another field, my Formula would simply be: $name

    I recommend reviewing the Sugar Logic documentation to review additional details about the available functions.

    Regards,

    Dan Kallish

    Advanced Support Engineer

    SUGARCRM

    Learning Resources: http://support.sugarcrm.com | http://university.sugarcrm.com | http://community.sugarcrm.com

  • Hello Cédric,

    I haven't tested this with a file field, but assuming it behaves as any string, you can extract a portion of the file name using the subStr function. Fortunately, your file-naming convention is standardized. Where the file name is "yyyy-mm - contract number - name of client.pdf", the contract's number is always preceded by 10 characters. Hopefully, the internal number is also a set number of chars. For this example, let's assume it's 6 digits.

    The formula for contract_number would be as follows, where 10 is the position of the first char to extract (that's actually the 11th, because the first character is position 0) and 6 is the length of the text you want.

    subStr($contract_attachment,10,6)

    Update: just noticed you want the yyyy-mm included. That would be:

    subStr($contract_attachment,0,16)

    Give it a try and let us know if that works!

    Best regards,

    Jill Shaheen

  • Hi jshaheen,

    Your answer seems to be the one to use in this specific case. However, if your formula does work with all the other fields, it didn't work with the file field. Was worth the try though!

    Thanks again for your contribution! I did learn something that may be useful in the future!