Add notes to custom module

Hi all, we had a developer add a custom module Feature Keys (holo_FeatureKeys)  to our Sugar Ent 9.0. I now need to add notes support to this module.

Using studio I created a relationship one-to-many in the feature key module to notes (see attached) however when I try and create a note and attach it to the feature-keys module  it does not show in the related to field. I understand the related to field in notes is a flex relate field so I don't understand why I cant see my Feature Key module. I trie a quick repair and rebuild but this did not fix it.

I tried adding a note via the api 

    public function createNote($api, $args) {
      $db = $GLOBALS['db']->getConnection();
      $result = [
        'totalSize'   => 0,
        'done'        => true,
        'success'     => false,
      ];

      $note = BeanFactory::getBean('Notes');
      $note->description        = 'Custom Holokote Image: '.$args['file_ext'];
      $note->id                 = create_guid();
      $note->new_with_id        = true;
      $note->filename           = $args['file'];
      $note->parent_type        = $args['parentType'];
      $note->modified_user_id   = $args['contact'];
      $note->created_by         = $args['contact'];
      $note->parent_id          = $args['parentID'];
      $note->file_mime_type     = $args['file_mime_type'];
      $note->file_ext           = $args['file_ext'];
      $note->file_size          = $args['file_size'];
      $note->save();

      if (isset($note->id) && !empty($note->id)) {
        $result['success'] = true;
        $file = $GLOBALS['sugar_config']['upload_dir'] . '/' . $note->id;
        sugar_file_put_contents($file, base64_decode($args['file_content']));
      }
      return $result;
    }

where $args['parent_type'] = holo_FeatureKey and the parent_id is set to the id of the newly created feature-key.

Am i missing a step or is there some custom code that is stopping this module showing in the notes related to field. All our other custom modules show.

I have also tried to add this to the dropdown list record_type_display_notes

Parents
  • clicked answered by mistake and cant set back to unanswered so still looking for help with this

  • My guess is that the note is being created and related correctly, you are just missing the parent name in the parent dropdown (as you may know when you use a value that is not in the dropdown you just don't see the value on the front end though it is actually in the database).

    The allowable parents for a flex relate field are defined in the dropdown called "parent_type_display".

    If you go to Admin->Dropdown Editor and find that dropdown you can add your custom module to it. 
    I believe the name needs to be your module's exact name: holo_FeatureKeys while the display label can be whatever you want it to be.

    FrancescaS

    PS. Note that you will now see your new module in every flex-relate dropdown.

  • thanks for clearing that up Francesca Shiekh will try your solution and see how I go, I take it i will have to add these file changes to a manifest package it up to install on my live cloud server

  • Sugar Studio can do the work for you if you add a relationship between your custom module and "Activities".  Note that this will also add relationships for Calls, Meetings, Tasks and Emails.

  • thanks @Justin, that create an additional field in my notes which I dont want, I just want to create the relationship with the related to field

  • Did you test adding the relationship to "Activities"?  It correctly uses the "Related To" field.

  • I see where you are going with this, adding the Activities certainly works but also adds Meetings, Tasks, Emails and Calls to the module - which may not be what we want.

    I tried it today in my development environment to see if I could add them all that way and then delete the relationships I didn't want, and instantly regretted it, it added so many files and removing the unwanted relationships was such a chore I just dumped my dev environment and rebuilt it.

    I am rethinking this whole thing.

    I'll be doing some more experiments.

    FrancescaS

  • I mentioned that it will add the Meetings, Tasks, Emails and Calls relationships.  I made my suggestion for a few reasons:

    • Many people don't know how to write the custom code or upload it to the Cloud.
    • It's easier to write and module load few custom files that hide the unwanted subpanels than it is to create custom files to add what you need for functioning relationships.
    • The Studio does create many files.  All of those files may be necessary for the correct functioning of the subpanel as well as the relationship elsewhere in the system.  Where possible, I prefer to let Sugar tools do the work for me as I've inherited too many instances where custom code was written incorrectly or incompletely and I can't get Support for the problems that arise.
  • I see your point of view Justin Kuehlthau, and it is an easy solution but, in my opinion, not a very clean one. Personally I don't like adding pieces that are not needed.

    André Lopes do you have a suggestion for how to add Notes but not Meetings, Calls, Tasks and Emails to a custom module?

    thank you,
    FrancescaS

  • Hi there

    This is a customization to be accomplished by hand, without Studio stuffs.

    1. Add an entry in the dropdowns record_type_display_notes and parent_type_display
    2. In the parent module create an extended vardefs and set the link field notes, just like it is defined in Accounts module, mind you have to update the value of 'relationship' attribute. Also set the relationship between parent module and Notes, just like defined in the Accounts module, mind you also have to replace string 'Accounts' by the appropriate one
    3. In the parent module create an extended language and seet the label for LBL_NOTES
    4. In th Notes module create an extended vardefs and set the id field <parent_module>_id, just liked the one defined for Accounts. Also set the link field <parent_module>, which has a relationship the one you just created in the parent module
    5. In the Notes module create an extended language and set the label for LBL_<PARENT_MODULE>_ID
    6. In the parent module create an exended client/base/layout an in there set the subpanel notes, just like the one in Accounts. Make sure you properly setup the link name and label

    Go to Admin -> Repair and run:

    • Quick Repair and Rebuild
    • Rebuild Relationships

    Clear browser cache and enjoy it!!

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
Reply
  • Hi there

    This is a customization to be accomplished by hand, without Studio stuffs.

    1. Add an entry in the dropdowns record_type_display_notes and parent_type_display
    2. In the parent module create an extended vardefs and set the link field notes, just like it is defined in Accounts module, mind you have to update the value of 'relationship' attribute. Also set the relationship between parent module and Notes, just like defined in the Accounts module, mind you also have to replace string 'Accounts' by the appropriate one
    3. In the parent module create an extended language and seet the label for LBL_NOTES
    4. In th Notes module create an extended vardefs and set the id field <parent_module>_id, just liked the one defined for Accounts. Also set the link field <parent_module>, which has a relationship the one you just created in the parent module
    5. In the Notes module create an extended language and set the label for LBL_<PARENT_MODULE>_ID
    6. In the parent module create an exended client/base/layout an in there set the subpanel notes, just like the one in Accounts. Make sure you properly setup the link name and label

    Go to Admin -> Repair and run:

    • Quick Repair and Rebuild
    • Rebuild Relationships

    Clear browser cache and enjoy it!!

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
Children