Search code examples
odatasapui5

Prepopulating Edit page for the row (Item) which has two keys in SAP UI5


This is my Item level page which has two Keys Request ID , Profile ID.

By selecting the item and on pressing the Edit Button, i should display the edit page with the data.

enter image description here

Code for Edit Button press

this.getRouter().getTargets().display("CreateCandidate", {
            mode: "update",
            objectPath: sObjectPath
        });

Here I'm getting

sObjectPath = "ZRECRUITMENT_CANDIDATESet(RegNo=1,ProId=1)"

My manifest.json

"CreateCandidate":{
                "viewName": "CreateCandidate",
                "viewId": "cand_creation",
                "viewLevel":2
            },

In the edit page, what should i bind to the FORM & what should be my pattern URL for the edit page.

For header row, we will give ZENTITY_SET/1 kind of.

But if we have two keys, how we will give the Pattern . Is it like ZENTITY_SET/1/2 ? please guide me regarding this

My ODATA read query :

/sap/opu/odata/SAP/ZRECRUITMENT_TRACKER_APP_SRV/
ZRECRUITMENT_CANDIDATESet(RegNo=1,ProId=2)?$format=xml

My OData Response:

<?xml version="1.0" encoding="UTF-8"?>
-
<entry
	xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="http://ttpl001.truspeq.com:8000/sap/opu/odata/SAP/ZRECRUITMENT_TRACKER_APP_SRV/"
	xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
	xmlns="http://www.w3.org/2005/Atom">
	<id>http://ttpl001.truspeq.com:8000/sap/opu/odata/SAP/ZRECRUITMENT_TRACKER_APP_SRV/ZRECRUITMENT_CANDIDATESet(RegNo=1,ProId=1)</id>
	<title type="text">ZRECRUITMENT_CANDIDATESet(RegNo=1,ProId=1)</title>
	<updated>2018-07-19T20:09:00Z</updated>
	<category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" term="ZRECRUITMENT_TRACKER_APP_SRV.ZRECRUITMENT_CANDIDATE"/>
	<link title="ZRECRUITMENT_CANDIDATE" href="ZRECRUITMENT_CANDIDATESet(RegNo=1,ProId=1)" rel="self"/>
	<link title="TOSALESDATA" type="application/atom+xml;type=entry" href="ZRECRUITMENT_CANDIDATESet(RegNo=1,ProId=1)/TOSALESDATA" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/TOSALESDATA"/>-
	<content type="application/xml">-
		<m:properties>
			<d:RegNo>1</d:RegNo>
			<d:ProId>1</d:ProId>
			<d:NameOfCan>ROCKY</d:NameOfCan>
			<d:Exp>4 YEAR</d:Exp>
			<d:CurrentCtc>45000</d:CurrentCtc>
			<d:ExpCtc>750000</d:ExpCtc>
			<d:NoticePeriod>3 MONTH</d:NoticePeriod>
			<d:CurrentLoc>KOLKATA</d:CurrentLoc>
			<d:CurrentCom>TCS</d:CurrentCom>
			<d:PassportDet>HHHWWQQ77</d:PassportDet>
			<d:PhoneNum>77778585</d:PhoneNum>
			<d:Email>[email protected]</d:Email>
			<d:SkypeId>7745</d:SkypeId>
		</m:properties>
	</content>
</entry>


Solution

  • See the docs for configuring the router here

    in manifest.json:

    ...
    "routes" : [
        {
            name: "createCandidate",
            pattern: "create/{RegNo}-{ProId}",
            target: "CreateCandidate"
        }
    ],
    "targets": {
        "CreateCandidate": {
            "viewName": "CreateCandidate",
            "viewLevel": 2
    },
    ....
    

    then to nav to that view:

    oRouter.navTo("createCandidate", {
        RegNo: 1
        ProId: 1
    })
    

    then in the CreateCandidate controller

    _onPatternMatched: function(oEvent) {
        // get the params RegNo and ProId from the event object - {RegNo: 1, ProId: 1}
        var oArgs = oEvent.getParameter("arguments"); 
    
        //use the ODataModel to create a binding path from the values
        var sBindingPath = this.getView().getModel().createKey("/ZRECRUITMENT_CANDIDATESet", oArgs);
    
        //Bind your view to the binding path
        this.getView().bindElement(sBindingPath); 
    }
    
    onInit: function() {
         //get the route object from the router
         var oRoute = this.getOwnerComponent().getRouter().getRoute("createCandiate");
    
         //attach an event to the route which is fired when the route pattern is matched
         oRoute.attachPatternMatched(this._onPatternMatched, this);
    }