Wednesday, August 7, 2013

Open UI Scenario 2 --> In Account Form Applet Hide/Unhide Phone Number and Fax Number depending on Address field


Open UI Scenario 2 --> In Account Form Applet Hide/Unhide Phone Number and Fax Number depending on Address
by jo [joju2002@gmail.com]

if the Address field is blank we will hide above two fields. If the Addres field having some values we unhide those two fields we have to make

Solution :
Step1: Create new PM
Step2: Create New PR
Step3:Update the Manifest file

PM Code Below 

// check it is already present
if( typeof( SiebelAppFacade.AccountFormPM_Jo ) === "undefined" ){

// add the namespace
    SiebelJS.Namespace( "SiebelAppFacade.AccountFormPM_Jo" );

// Key
    SiebelApp.S_App.RegisterConstructorAgainstKey( "AccountFormPM_Joodel", "SiebelAppFacade.AccountFormPM_Jo" );


    SiebelAppFacade.AccountFormPM_Jo = ( function(){

// call the superclass
        function AccountFormPM_Jo( proxy ){
            SiebelAppFacade.AccountFormPM_Jo.superclass.constructor.call( this, proxy );
        }

// extend the presentation model
        SiebelJS.Extend( AccountFormPM_Jo, SiebelAppFacade.PresentationModel );

// For PM we need init method
        AccountFormPM_Jo.prototype.Init = function(){
            SiebelAppFacade.AccountFormPM_Jo.superclass.Init.call( this );
            this.AddProperty( "ShowAddressRelatedField", "" );
            this.AddMethod( "ShowSelection",  SelectionChange, { sequence : false, scope : this } );
            this.AddMethod( "FieldChange",  OnFieldChange, { sequence : false, scope: this } );
        };

// Custom function: When a new record is selected, set ShowAddressRelatedField to true or false, depending on
 function SelectionChange(){
            var controls = this.Get( "GetControls" );
            var control = controls[ "StreetAddress" ];
            var value = this.ExecuteMethod( "GetFieldValue", control );
            this.SetProperty( "ShowAddressRelatedField", ( value ? true: false ) );
SiebelJS.Log("The value of ShowAddressRelatedField is " + this.Get( "ShowAddressRelatedField"));
        }


// street address field, determine whether or not it is now empty, and set ShowAddressRelatedField accordingly.
        function OnFieldChange( control, value ){
            if( control.GetName() === "StreetAddress" ){
                this.SetProperty( "ShowAddressRelatedField", ( value ? true: false ) );
SiebelJS.Log("The value of ShowAddressRelatedField is " + this.Get( "ShowAddressRelatedField"));
            }
        }
        return AccountFormPM_Jo;
    }());
}



PR Code Below 

if (typeof (SiebelAppFacade.AccountPartialRefreshPR) === "undefined") {
    SiebelJS.Namespace("SiebelAppFacade.AccountPartialRefreshPR");
    SiebelApp.S_App.RegisterConstructorAgainstKey( "AccountPartialRefreshPR", "SiebelAppFacade.AccountPartialRefreshPR" );
    SiebelAppFacade.AccountPartialRefreshPR = ( function(){
SiebelJS.Extend( AccountPartialRefreshPR, SiebelAppFacade.PhysicalRenderer );
                               
        function AccountPartialRefreshPR( pm ){
            SiebelAppFacade.AccountPartialRefreshPR.superclass.constructor.call( this, pm );
            this.GetPM().AttachPMBinding( "ShowAddressRelatedField",  ModifyLayout, { scope: this });
        }
 
        function ModifyLayout( ){
            var controls = this.GetPM().Get( "GetControls" );
            var canShow = this.GetPM().Get( "ShowAddressRelatedField" );
            var WorkPhoneNum = controls[ "MainPhoneNumber" ];
            var FaxPhoneNum = controls[ "MainFaxNumber" ];

            if( canShow ){
                $( "span#MainPhoneNumber_Label" ).parent().fadeIn(500);
                $( "[name='" + WorkPhoneNum.GetInputName() + "']" ).fadeIn(500);
                $( "span#MainFaxNumber_Label" ).parent().fadeIn(500);
                $( "[name='" + FaxPhoneNum.GetInputName() + "']" ).fadeIn(500);
            }
            else{
                $( "span#MainPhoneNumber_Label" ).parent().fadeOut(500);
                $( "[name='" + WorkPhoneNum.GetInputName() + "']" ).fadeOut(500);
                $( "span#MainFaxNumber_Label" ).parent().fadeOut(500);
                $( "[name='" + FaxPhoneNum.GetInputName() + "']" ).fadeOut(500);
            }
}
        return AccountPartialRefreshPR;
    }());

}


Step 3
Update the Manifest and custom_Manifest.xm file

Note: Make sure you clear the history of your browser[With IP 2013 they will remove this issue. IP2013 will be launching on Nov 2013]

Account having address field having value 
Account having address field null. in this case two fields become hidden