You are browsing the documentation for iTop 3.0 which is not the current version.

Consider browsing to iTop 3.2 documentation

Optional relationship on Portal

In this tutorial, we will see how to make an n:n relationship dynamically optional, based on Service Subcategories.

Let say that you want to request the user to select some Application Solutions when creating a UserRequest in the Portal, but only for some services subcategories, for the others, you don't want the user to be bothered with that.

  1. Add a field with_as (enum yes/no) on the Service Subcategory, to store if the n:n relation “Application Solutions” must be prompted to the User
  2. Create an applicationsolutions_list LinkedSetIndirect on the UserRequest class and make it dependent of servicesubcategory_id
  3. Create an ExternalField with_as on User Request, to get the equivalent field from servicesubcategory_id
  4. Modify the Portal creation and modify forms for Ticket, to add applicationsolutions_list
  5. Overwrite UserRequest::GetAttributeFlags() to hide applicationsolutions_list when applicable

🚧 provides more details of each steps 🚧 Test the behavior on Console ?

Class UserRequest
public function GetInitialStateAttributeFlags($sAttCode, &$aReasons = array())
{
       if (($sAttCode == 'applicationsolutions_list') && \ContextTag::Check(\ContextTag::TAG_PORTAL) && $this->Get('with_as') =='no')
        {
            return(OPT_ATT_HIDDEN | parent::GetInitialStateAttributeFlags($sAttCode, $aReasons));
        }
        return parent::GetInitialStateAttributeFlags($sAttCode, $aReasons);
}
 
public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
{
        if (($sAttCode == 'applicationsolutions_list') && \ContextTag::Check(\ContextTag::TAG_PORTAL) && $this->Get('with_as') =='no')
        {
            return(OPT_ATT_HIDDEN | parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState));
        }
        return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
}
3_0_0/customization/portal_howto_dynamic_link.txt · Last modified: 2022/05/03 18:00 by 127.0.0.1
Back to top
Contact us