cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in deleting rows

Former Member
0 Kudos

Hi experts,

in the following method. I am deleting the records from the BAPI output table where the date and month do not correspond to todays date and current month.

When I execute the BAPI for one employee it gives me the correct output. ie one record. But when I execute it for all the employees and when I use the following code. It gives me a blank output.


  public void wdDoInit()
  {
    //@@begin wdDoInit()
    int date_today, current_date;
    int month_today, current_month;
    char date_satisfied, month_satisfied;
    Date date = new Date(System.currentTimeMillis());
    date_today = date.getDate();
    month_today = date.getMonth();
    
	int n = wdContext.nodeBirhtday_List().nodeItab().size();
	int leadSelected = wdContext.nodeBirhtday_List().nodeItab().getLeadSelection();
	//	loop backwards to avoid index troubles
	for (int i = n - 1; i >= 0; --i) {
 		current_date  = wdContext.nodeBirhtday_List().nodeItab().currentItabElement().getGbdat().getDate();
 		current_month = wdContext.nodeBirhtday_List().nodeItab().currentItabElement().getGbdat().getMonth();
 		
 		if (( current_date != date_today ) && ( current_month != month_today ))
 		{
			wdContext.nodeBirhtday_List().nodeItab().removeElement(wdContext.nodeBirhtday_List().nodeItab().
						getElementAt(i)); 
 		}
		
			}	
    //@@end
  }

can anybody please suggest me the solution

Regards

Abdullah

Accepted Solutions (1)

Accepted Solutions (1)

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi,

for looping in the output node, you should write

<output node>.moveNext(); //in for loop

so as to move to next record , other wise it will compare with same record again and again.

and also add

<output node>.moveFirst(); //before the for loop(outside)

hope it helps

regards

Former Member
0 Kudos

Hi Abhijeet,

I tried it the way you said using


 	wdContext.nodeBirhtday_List().nodeItab().moveFirst();
	//	loop backwards to avoid index troubles
	for (int i = n - 1; i >= 0; --i) 
	{
		
 		current_date  = wdContext.nodeBirhtday_List().nodeItab().currentItabElement().getGbdat().getDate();
 		current_month = wdContext.nodeBirhtday_List().nodeItab().currentItabElement().getGbdat().getMonth();
 		
 		if (( current_date != date_today ) && ( current_month != month_today ))
 		{
			wdContext.nodeBirhtday_List().nodeItab().removeElement(wdContext.nodeBirhtday_List().nodeItab().
						getElementAt(i)); 			
 		}
		wdContext.nodeBirhtday_List().nodeItab().moveNext();	
	
	}

It adds records...

According to Valerys Solution, the IPrivate<CustomController> doesnt show me the required nodes. and gives me 'Unable to resolve' error.

Can you please suggest where I am going wrong

Regards

Abdullah

Former Member
0 Kudos

Abdullah,

<i>According to Valerys Solution, the IPrivate<CustomController> doesnt show me the required nodes. and gives me 'Unable to resolve' error.</i>

I've used IPrivate<ControllerName> as a placeholder, you must substitute it with actual name of controller class -- like IPrivateCustomController or IPrivateMyComponentController.

VS

Former Member
0 Kudos

I too had used IPrivateBirthdayCust but i get only two options. One is class and the other is WDActionEventHandler.

Regards

Abdullah

abhijeet_mukkawar
Active Contributor
0 Kudos

Abdullah,

I am sorry , that i suggested moveNext and moveFirst, since in your case it is starting from backward,

your code is fine , but what i think you are skipping is moving to previous record, when it is run for just one record, that is acting as current record and it is getting executed fine. but when you have more than one record , you are looping right but you are not moving to previous recor, so add

node.movePrevious();//just before the end of for loop(but in loop)

and

node.moveLast();//just before the start of for loop(outside loop)

keep your code as you have used earlier and remofe my earlier suggestion.

it will work

let me know if you face problem

regards

Former Member
0 Kudos

Hi,

Abhijeet, Sorry but I am still not getting it right.

I am unable to make use of Valerys method too can any body please help me out.

Regards

Abdullah

Former Member
0 Kudos

Abdullah,

Type IPrivateBirthdayCust instead of IPrivate<ControllerName> in my example, then right-click on source and select "Organazie imports" from pop-up menu

VS

Former Member
0 Kudos

Dear Valery and Abhijeet,

Thanks a lot for the time you spent in helping me out. The problem was infact solved by both of you. I tried Abhijeets method first and then Valerys method. Both gave me the same output. And the silly mistake was on my part that I was using the && operator in the if condition rather than || operator. I wish I could have given you both 10 points. But its going to be only one person.

Regards

Abdullah

Former Member
0 Kudos

Abdullah,

You found a really smart way to assign equal amount of points )

VS

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Abdulla,

If your above requirement is on load of the view then may be you can eliminate getting those value populated based on the condition in the backend.

but if you dont have access to the backend and you nedd to do it in the code itsself then you need to follow Valery's advice (i.e accessing the element based on indexing)

Former Member
0 Kudos

hi

good

this

for (int i = n - 1; i >= 0; --i) executing once so that it is giving the correct result for the one employee,check this code in the debug mode ,if it is working for only one employee than put this inside the loop and see the difference.

thanks

mrutyun^

Former Member
0 Kudos

Abdullah,

You are comparing filter values with currently selected row, but now tih row at index. Should be:


public void wdDoInit()
{
  //@@begin wdDoInit()
  int date_today, current_date;
  int month_today, current_month;
  char date_satisfied, month_satisfied;
  Date date = new Date(System.currentTimeMillis());
  date_today = date.getDate();
  month_today = date.getMonth();
  
  final IPrivate<ControllerName>.ItabNode node =  wdContext.nodeBirhtday_List().nodeItab();
  // loop backwards to avoid index troubles
  for (int i = node.size() - 1; i >= 0; --i) {
    final IPrivate<ControllerName>.ItabElement el = node.getItabElementAt(i);
    current_date    = el.getGbdat().getDate();
    current_month = el.getGbdat().getMonth();
 		
    if ( ( current_date != date_today ) && ( current_month != month_today ) )
      node.removeElement(el);
  }
  //@@end
}

Valery Silaev

SaM Solutions

http://www.sam-solutions.net