can i turn leadās form to be readonly if status of lead is changed to be closed or converted
it only gives two options to move or copy none are to disable lead
Are you able to work with hooks? you could e.g. remove a security group from a lead as soon as it is āclosedā/converted. Assuming that the security group grants the edit right, the lead would be read-only after removing the group.
can you please give a code example
sure, you can find examples in the documentation: Logic Hooks :: SuiteCRM Documentation
If I were you, I would try to start with an after-save-hook for leads. in that hook, you unset the relationship to the security group that is related to the lead. so if this is your approach, you need to setup the security group/permissions first (otherwise your hook might work and remove the securitygroup, but the contact remains editable).
0 =>
array (
'name' => 'last_name',
'label' => 'LBL_LAST_NAME',
'customCode' => '<input type="text" tabindex="0" value="{$fields.last_name.value}" maxlength="99" size="30" id="last_name" name="last_name" {$readOnly}>',
),
in detailviewdefs
class LeadsViewDetail extends ViewDetail{
public function __construct()
{
parent::__construct();
$this->useForSubpanel = true;
$this->useModuleQuickCreateTemplate = true;
}
public function display()
{
global $current_user;
if( $this->bean->status=='Closed'){
$isClosed=false;
}
// Set the $readOnly variable based on the user's administrator status
$readOnly = $isClosed ? '' : 'readonly = "readonly"';
// Assign $readOnly to Smarty template
$this->ev->ss->assign('readOnly', $readOnly);
parent::display(); // Call the parent display function to render the view
}
}
in detail.view.php
canāt i use this method
Is it working? Did you create test lead and try it?
No it is not
Last name field is always read only now I donāt understand why
You added customCode for last_name to be readonly field
What about this logic hook code?
class LeadReadOnlyHook
{
public function before_save($bean, $event, $arguments)
{
if ($bean->status === 'Closed' || $bean->status === 'Converted') {
$bean->is_readonly = true;
} else {
$bean->is_readonly = false;
}
}
}
I thought it was conditional
I didnāt think this was an option thank you will try it
Do you think this is better one?
$readOnly = $isClosed ? 'readonly="readonly"' : ' ';
i tried this but it didnāt work
I think you can disable the āEditā or āSaveā button to restrict changing the data once closed or converted the lead. The detail view is view-only.
Disabling the Edit button might not be enough, because of those little āpencilā buttons on each field (similar to the old āInline Editā buttons).
Disabling Save might work.
Any way I am thinking that the correct way to do this is through the ACLās, which provide the basic security access and control whether a user has access to read or read/write a record.
What we would need to do is manipulate the handling of the ACLās to make it conditional, dependent on data on the field. I see a way of doing this, which is by sub-classing the RecordHandler
class in custom and overriding the getRecord
method. But this is somewhat complex and it would take me quite some time to figure it out and explain it, and I am afraid I donāt have that much time
'customCode'=>'{if $fields.status.value !== "Closed"}@@FIELD@@{else}<div style=\'visibility:visible\' disabled="true" id="last_name" ></div>{/if}'
i am trying this code but it makes field always readonly