Skip to Content

Consider that you have created a Fiori application (Smart or not) with multiple filters and tables. In such a case you might want to help the users by providing default values to various filters, table columns etc. You can achieve that by creating Global Variants. But users still have to explicitly select this Global Variant you created and set as ‘default’.  There is no SAP provided way as of now to set a Global Variant as default to all the users. Hope SAP provides this feature one day. Till then here is the programmatic solution.

Important note: Like many of my blogs, this is a hack. Which means this is not an SAP documented supported scenario. So SAP does not guarantee that these APIs will work seamlessly across upgrades. Thanks Prasita Prabhakaran for pointing that.

So lets get started!

Step 1. Create a new Workbench Transport (TCode SE10) in your Gateway system. This is used to store the Global Variant that you are going to create and move it all the way to Production.

Step 2. Open the Fiori application under consideration. Set the application status by selecting various filter values, selecting columns of tables, selecting width of layouts so on.

Step 3. Save this Variant as a Public Variant, by selecting the checkbox as shown below. Moment you check this box, you will be prompted for a transport request. Select the transport request you created in Step 1.

Step 4. At this point, you have the Global Variant and it is available to all users. Now you need to set this as default to all. First we need to find the technical id of this Variant. Refresh the application with Developer Tools open. Under network tab, filter the requests by search term ‘lrep/flex’. Under the Preview tab, open the response. Under ‘changes’, there will be two entries with ‘fileType’ as “variant”. First entry is for the SAP delivered “Standard” variant. Second one is for the new Global Filter you created in Step 3. Copy the content under property “fileName”. This is the technical name of your Global Variant.

 

Step 5. Open the Fiori application where you need to set the default Variant. If it is a free-style application, you can do it in onAFterRendering event of the Controller. If it is an OVP, you need to create a custom controller and write in onAfterRendering event handler.

 

onBeforeRendering: function(){
	//Get reference to a control which has Variant management
	var oSmartFilter = this.getView().byId("ovpGlobalFilter");

	//Set the Global Variant as the current Variant
	oSmartFilter.getVariantManagement().setCurrentVariantId("id_1535046664297_171_page");
}

 

Step 6. If the user has already defaulted a Variant, then you do not want to overwrite that Variant. So ensure that you set the default Variant only if the user does not have a default Variant. Check the self explanatory code below.

onBeforeRendering: function(){
	//Get reference to a control which has Variant management
	var oSmartFilter = this.getView().byId("ovpGlobalFilter");
	
	//Ensure that there is no default Variant set by the user. 
	//In such a case, do not set default Variant.
	var sDefaultVariantKey = oGlobalFilter.getVariantManagement().getDefaultVariantKey();
	
	//If No variant is set, default variant is "standard"
	if (sDefaultVariantKey !== "*standard*"){  
		return;
	}

	//Set the Global Variant as the current Variant
	oSmartFilter.getVariantManagement().setCurrentVariantId("id_1535046664297_171_page");
}

 

Hope it was helpful !!

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply