Sidebar

Using iTop

Creating your iTop

iTop Customization

"How to" examples
DataModel

User Interface

Automation & Ticket management

Portal Customization

:: Version 3.2.0 ::

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

FIXME provides more details of each steps FIXME 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_2_0/customization/portal_howto_dynamic_link.txt · Last modified: 2024/09/10 10:25 by 127.0.0.1
Back to top
Contact us