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

  • 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 Francesca Shiekh , I added it to the list you mentioned but still no joy, i havee noticed if i create a new note i now get a feature key box where i can attach the note to the feature key. Freature key is now in the related list but this does not create a link to the feature key

  • I think what is happening is that we are mixing things.

    You can either add a relationship between Notes and Feature Keys - which will add a field for Feature Keys to Notes.

    OR 

    You can add Feature Keys to the Parent dropdown so that a Feature Key can be related to the Note via the flex-relate.

    I would do as follows: remove the newly created relationship so it removes the added field (you don't want that to appear on all Notes).

    <corrected> Add your module to "record_type_display_notes" and "parent_type_display" dropdown. 

    Now see if you can create a Note with flex relate parent Feature Keys.

    To get a subpanel on Feature Keys for your Notes see the "Correct Answer" here:

    https://community.sugarcrm.com/thread/30169-what-is-the-best-way-to-add-a-subpanel-for-module-related-via-flex-relate

     

    FrancescaS

  • 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

  • I work on an on-site instance so I'm not too familiar with cloud but to the best of my understanding that's the only way to add files to cloud.

  • 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

1 2