Field Mapping from customers module to a custom module

@lucid
It work not correct:

  • the logichook “after_relationship_add” work for all modules wiche have relationship with “Moves_Moves”.
  • the field “$bean->moves_moves_accounts” isn’t id type, it’s link type.

I see a few ending in ida, idb in the cache for relationships, what does an ID usually look like?

It is may be them. There is documentation: https://docs.suitecrm.com/developer/vardefs/#_defining_vardefs
and you can look at files: vardefs.php .

ok I think I sorted that part out, but that doesn’t fix the error that it doesn’t recognize

$bean_account = new Accounts()

nor

$bean_customer = new Customers();

So the linking wouldn’t work because it happens afterwards

Hi again, I was working on another project in the meantime. Just coming back to this issue now. I searched vardefs and found an id_name for the relationship between the customers module and the moves_moves module. When I use the singular ‘$bean_account = new Account;’ I do not get any errors, but I’m still stuck with what could be going wrong here.

$relateID = 'moves_moves_accountsaccounts_ida'; $bean_account = new Account(); $bean_account->retrieve($relateID); $bean->movescustomerphone = $bean_account->phone_office;

So now I have no errors in my PHP file, but it still confuses me why the customer’s phone number isn’t there. Is there a way I can see if this retrieve function is even pulling anything? I’m assuming it’s just making a new null Account and not filling any of the fields from the database. I don’t know how to proceed at this point, tried a lot of methods to get this done and it seems very simple but nothing is working.

@lucid
“moves_moves_accountsaccounts_ida” isn’t id of module. It is id of relationship. I can’t help you if I don’t see naming of your fields.

Ok thank you, I appreciate the help. Taking some screen grabs right now

@lucid
I wrote already.

Clients Fields (This is just a renaming of the Accounts module):


clients fields 2
phone_office is the active field, which i would like to obtain by the moves module

Moves Fields:



moves fields 3
movescustomerphone is where i would like to pull the phone number after i selected my client

Moves Relationships:


This is the relationship, it is one client to many moves. In case there are repeat customers

This is the beginning of the Accounts vardefs.php file, I see that there is ‘id’ right at the top, I think what I am confused about is the difference between a module ID vs a relationship ID. I’ve been using the IDs shown in the relationships vardefs which i suppose would be wrong from what you’ve stated earlier.
accountsvardef

@lucid
There aren’t information about fields witch type is id on this screenshots. It is only in files.

I found this is in the cache of the Moves_Moves module, that is the field where the user chooses a client(account). I tried using ‘account_id_c’ but it didn’t work. Sorry if this is taking a long time, I’m still grasping suitecrm

@lucid
You can use the next logic hook “after_save”. It work after you save Account record.
the file custom/modules/Accounts/logic_hooks.php

$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1,'After save','custom/modules/Accounts/PhoneGrab.php','PhoneGrab','copy');

the file custom/modules/Accounts/PhoneGrab.php

class PhoneGrab{
    function copy(&$bean, $event, $arguments){
        $bean_customer = new Moves_Moves();
        $bean_customer->retrieve_by_string_fields(array('account_id_c' => $bean->id));
        $bean_customer->customerphone_c=$bean->customerphone_c;
        $bean_customer->save();
    }
}

I remember running some after_save code earlier with this issue and ended up in a save loop, is there a way I can prevent that here?

This is a different code. Look carefully at the filenames and their contents.

just tried that code out, whenever I save I get a blank move record generated but the phone number still doesn’t transfer over

“account_id_c” isn’t correct field. To look at files details. It isn’t difficult.

i used the original fields which are in my layout, I changed your values to mine. Also, I’ve tried this code with pretty much anything that had ‘id’ in it from my vardefs, so I’m not even sure what I should be looking for anymore.