Auto-populate Client field in Case Module

I’m hoping someone can point me in the right direction. I appreciate your help.
I’ve read about logic hooks, but I still can’t figure this one out.

We’ve created a one-to-one relationship between the Cases and Contacts modules.
What I’d like to do is auto populate the Contact (Client) name when creating a new case via the subpanel we have in the Contacts Detail page.
See attachment called: create_subpanel.png

The attachment called: field_autopopulate.png shows the field we’d like to auto populate.

Thought it might help to include the source code for the fields:

<div class="col-xs-12 col-sm-8 edit-view-field " type="relate" field="client_join_c"  >
<input type="text" name="client_join_c" class="sqsEnabled" tabindex="" id="client_join_c" size="" value="" title='' autocomplete="off"  	 >
<input type="hidden" name="contact_id_c" 
<span class="id-ff multiple">
<button type="button" name="btn_client_join_c" id="btn_client_join_c" tabindex="" title="Select Contact" class="button firstChild" value="Select Contact"
);' ><img src="themes/SuiteP/images/id-ff-select.png?v=4bxTP2wYOiQPbOKcuMKUww"></button><button type="button" name="btn_clr_client_join_c" id="btn_clr_client_join_c" tabindex="" title="Clear Contact"  class="button lastChild"
onclick="SUGAR.clearRelateField(this.form, 'client_join_c', 'contact_id_c');"  value="Clear Contact" ><img src="themes/SuiteP/images/id-ff-clear.png?v=4bxTP2wYOiQPbOKcuMKUww"></button>
<script type="text/javascript">
		"typeof(sqs_objects) != 'undefined' && typeof(sqs_objects['EditView_client_join_c']) != 'undefined'",

Is this possible?
Thank you so much!

Anyone have any idea on this one?
Thank you!

Any reason why you’re not using the default connection between Cases and Contacts? These modules are already connected, you can specify that a case pertains to a contact, and you get a button to select contact from a list like you want… what other requirements do you have?

Thank you so much for getting back to me pgr.

Instead of picking from a list of clients (with a button); I was hoping to have the client field auto-populate when creating a case from said client.
It would just save a step I think. Is this possible?

It already does that by default.

When you are in a contact’s detail view, go down to the “Cases” subpanel, click the “Create” button, you get a pop-up to add information about the case, and it is created linked to that contact, and to the contact’s account

I just tried it on the online demo…

Hmm, I think I may see the disconnect here.
We don’t use the Accounts module at all. (Only Cases and Contacts)
The online demo only auto-fills the Account. Please see attached. …and thanks again pgr.

You don’t need to use the Accounts module. I did everything from the Contacts module.

Maybe the disconnect is this: you’re looking for a field to be filled with the Contact; but it’s not a field, it’s a relationship.

It will get created automatically, so that when you are in the case, you will find the contact in a subpanel; and when you are in the contact, you will find the case in a subpanel.

You can get it to display like a simple field, if you really need to; but that is just a matter of how it is displayed. In the database it’s a relationship.

I understand why you expect a simple field: because for you this relationship is meant to be one-to-one. But by default in SuiteCRM it’s many-to-many, so the adequate display is the subpanel. You can either just work with this, or add some code to restrict the relationship or display things differently.

That sounds reasonable. Thank you. :slight_smile:
About adding code to restrict the relationship. Do you know of a forum topic that addressees this?
I can’t find one.

Hhmm I don’t really know. But it would have to be done in code, I hope you’re a developer.

You might want to check out Jim Mackin’s eBook, “SuiteCRM for Developers”, and read the section on logic_hooks. Maybe you can find something there to restrict when the relatioship is saving, but I’m not sure.

Good luck.

I have the e-book.
I’ll peruse the logic_hook section.
You’ve been a great help. I appreciate it immensely. :slight_smile:

That’s ok, I like helping out. :slight_smile:

Do you really need to restrict the relationship? Maybe you can just leave it as it is and ask users to keep it one-to-one.