AnsweredAssumed Answered

Custom validation SetRequired using Dependency

Question asked by Kishor Mali on Mar 15, 2019
Latest reply on Apr 2, 2019 by Kishor Mali

Hello Everyone,

 

I have custom requirement:

1) I have a custom field call_rating

2) It is required when Meeting status is "Held" and user having role "Sales".

3) In either condition it is not mandatory.

I am able to achieve this requirement using overriding create.js and record.js. But then it is not working in mobile view.

 

After reading this link, I come to know that I can achieve that using dependency. but still it is not working.

Also I have a doubt regarding the javascript block we have in code block.

https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_8.3/Architecture/Sugar_Logic/Using_Suga… 

 

My code:

<?php
global $current_user;
include_once('modules/ACLRoles/ACLRole.php');
$roles = getUserRoleNames($current_user->id);

require_once('include/MVC/View/views/view.edit.php');
require_once("include/Expressions/Dependency.php");
require_once("include/Expressions/Trigger.php");
require_once("include/Expressions/Expression/Parser/Parser.php");
require_once("include/Expressions/Actions/ActionFactory.php");

class MeetingsViewEdit extends ViewEdit
{

function MeetingsViewEdit()
{
parent::ViewEdit();
}

function display()
{
parent::display();
$dep = new Dependency("call_rating_required_dep");
$triggerExp = 'contains($status, "Held")';
//will be array('name')

$triggerFields = Parser::getFieldsFromExpression($triggerExp);
$dep->setTrigger(new Trigger($triggerExp, $triggerFields));

// if(in_array("Sales", $roles)){

//Set the description field to be required if "important" is in the call subject
$dep->addAction(ActionFactory::getNewAction('SetRequired', array(
'target' => 'call_rating_c',
'label' => 'Call Rating',
'value' => 'true'
)));
// }




//Set the description field to NOT be required if "important" is NOT in the call subject
$dep->addFalseAction(ActionFactory::getNewAction('SetRequired', array(
'target' => 'call_rating_c',
'label' => 'Call Rating',
'value' => 'false'
)));

//Evaluate the trigger immediatly when the page loads
$dep->setFireOnLoad(true);
$javascript = $dep->getJavascript();
echo
SUGAR.forms.AssignmentHandler.registerView('EditView');
{$javascript}
EOQ;
}
}

?>

 

Help is highly appreciated.

Outcomes