Wednesday, 6 September 2017

vlocity - Read parameters from url and pass those values to apex class from a vlocity UI template


Below code works for this scenario,


vlocity.cardframework.registerModule.controller('networkController', function($scope,dataService) {
 
   $scope.list={
        text1:'',
        text2:''
    };
 
    $scope.init=function(){
        //read url parameters
        var searchParams = new URLSearchParams(window.parent.location.search);
        var effective_date=searchParams.get("effective_date");
        var plan_type=searchParams.get("plan_type");
        var quote_Id=searchParams.get("quoteId");
        console.log('effective_date: '+effective_date);
        $scope.effective_date=effective_date;
        $scope.plan_type=plan_type;
        $scope.quote_Id=quote_Id;
        //pass those parameters to apex function
         var className = 'ProductAttributeRemote';
            var classMethod = 'getMedicalProducts';
            console.log('className :'+className);
            console.log('classMethod :'+classMethod);
            console.log('effective_date'+effective_date);
            console.log('plan_type'+plan_type);
            console.log('quote_Id'+quote_Id);
         
            if(className && classMethod) {
                var inputMap = {};
                inputMap.effective_date = effective_date;
                inputMap.plan_type = plan_type;
                inputMap.quote_Id = quote_Id;
               dataService.doGenericInvoke(className, classMethod,angular.toJson(inputMap),null)
               .then((data) => {
                    // Handle callout response
                   console.log('call out data:'+JSON.stringify(data));
                })
                .catch((error)=>{
                    // Handle error
                    console.log('error :',err);
                });
            }
    }
        // Your code goes here
$scope.changeMedicalPlans=function(){
    console.log('hi');
    //get url parameter

    var scp = $scope;
    console.log(scp);
   console.log('text1');
   var loc = window.location.toString();
   console.log(loc);
 
   var param = loc.split('?')[1],
    iframe = document.getElementById('iFrameResizer0');

iframe.src = iframe.src + '?' + params;
console.log('ifrmasrc'+iframe.src );
 
$scope.list.text1 = $scope.MedicalPlan;
$scope.$parent.$parent.updateDatasource($scope.list);
console.log($scope.list.text1);
}
$scope.changeDeductible=function(){
    console.log('text2');

$scope.list.text2 = $scope.Deductible;
$scope.$parent.$parent.updateDatasource($scope.list);
console.log($scope.list.text2);
}
   
//}])


//vlocity.cardframework.registerModule.controller('logoController', ['$scope', //function($scope) {

$scope.goldLogo=false;
$scope.silverLogo=false;
$scope.bronzeLogo=false;
 
   $scope.checkLogo=function(name){
     
      // console.log('Entered into check logo method');
     var logoName = name.split(/\s+/);
        if(logoName[0]==="Gold"){
            $scope.goldLogo=true;
            $scope.silverLogo=false;
            $scope.bronzeLogo=false;
            return true;
        }
        else if(logoName[0]==="Silver"){
            $scope.silverLogo=true;
            $scope.goldLogo=false;
            $scope.bronzeLogo=false;
            return true;
        }
        else if(logoName[0]==="Bronze"){
            $scope.goldLogo=false;
            $scope.silverLogo=false;
            $scope.bronzeLogo=true;
            return true;
        }
     
   };
   
});


place init method as

<div ng-controller="myCtrl" ng-init="init()"></div>



   

4 comments:

  1. Getting error:
    Cannot read property 'doGenericInvoke' of undefined
    Do i need to include some js file.?

    ReplyDelete
  2. vlocity framework itself provides the property 'doGenericInvoke', we just defined 'dataService' in controller itself. i.e,

    vlocity.cardframework.registerModule.controller('networkController', function($scope,dataService) {

    ReplyDelete
  3. i did the same but getting error. Can have some insight for it what can be the issue ?

    ReplyDelete
  4. I am using the syntax vlocity.cardframework.registerModule.controller('controllerName', ['$scope', function($scope,dataService)
    and i am viewing in preview mode

    ReplyDelete