Issue in Pagination in Service portal widget

Nikita35
Kilo Guru

Hello 

I am working on a menu item - My Approvals which should give me Pending Approvals, Approval history.

In approval history widget, I am trying to show 5 approvals at a time(On clicking "next", next 5 approvals will show up ) - which included all the states except Requested.

I'm trying to fetch records from sysapproval_approver table. and paginate them.

The pagination works fine for gr.addQuery('state','Requested'); 

Now I'm trying to make a widget for Approval History gr.addQuery('state','!=','Requested'); 

but the pagination for this changes everytime I click next button, It shows 3, sometimes 2 or sometimes 5 records, it is not consistent pagination.

I tried fetching only for approved state, but same thing. It seems to work well only for requested records for me.

I've tried fetching less records also, till some date, as I thought the issues might be large data, but same issue.

Kindly help ASAP. 

Regards

 

11 REPLIES 11

functions getNextSetFdx(fdx) {...} and getPreviousSetFdx(fdx) {...} are expecting parameter "fdx", which I guess is an object, but in the html buttons that are using these functions you are not passing anything.

Also I don't recommend using c.server.update() as it reloads whole page, you can reload partial data simply by using following syntax:

var payload = {
    "action": "your_action_name",
    "additional_data": additionalDataVariable,
}

c.server.get(payload).then(function(response) {
    console.log(response.data)
})

 

In the server script you increment a count "data.count++;" regardless if it passes one of the if statements and is pushed to array, that's probably the reason of bad count. Move the increment into both if statements.

while(approvalGRH.next()){
			data.count++;
			var approvalObjHist = {};
				
				var approvalNumberH = approvalGRH.document_id.number.toString();
				
				if(approvalNumberH.startsWith("RITM")){
					approvalObjHist.type = "Requested Item";
					approvalObjHist.number = approvalNumberH;
					approvalObjHist.sysID = approvalGRH.sys_id.toString();
					approvalObjHist.reqItemSysID = approvalGRH.document_id.sys_id.toString();
					approvalObjHist.date = approvalGRH.sys_created_on.toString();
					approvalObjHist.item = approvalGRH.document_id.cat_item.name.toString();
					approvalObjHist.state = approvalGRH.state.getDisplayValue().toString();
					data.approvalsHistory.push(approvalObjHist);
				}
				
				
				else if(approvalNumberH.startsWith("ApplAcc")){
					approvalObjHist.type = "Application Access";
					approvalObjHist.number = approvalNumberH;
					approvalObjHist.sysID = approvalGRH.sys_id.toString();
					approvalObjHist.reqItemSysID = approvalGRH.document_id.sys_id.toString();
					approvalObjHist.date = approvalGRH.sys_created_on.toString();
					approvalObjHist.item = approvalGRH.document_id.u_application.name.toString();
					approvalObjHist.state = approvalGRH.state.getDisplayValue().toString();
					data.approvalsHistory.push(approvalObjHist);
				}
				
				else{
					data.advancedApproval = true;
				}
				
			} ...

 

Also don't really get the "else" part of your if where you are setting "data.advancedApproval = true;" but that is another topic.

Thanks for the reply,

can you please explain this part

var payload = {
    "action": "your_action_name",
    "additional_data": additionalDataVariable,
}

the action is c.data.action how can i put this in this syntax?

and what will this additional data part contain?

 

Thanks.

SatheeshKumar
Kilo Sage

I think you need to increment both page size and current page every time to get consequent records but in your code you are just incrementing the current page , so it reduces the number of records displayed everytime.

also you are passing index of records not the page index so you need to reduce /increment the values by 5 for each button click but you are adding/reducing only 1. 

check the below definition of choose window.

chooseWindow(Number firstRow, Number lastRow, Boolean forceCount)

Sets a range of rows to be returned by subsequent queries.

Parameter(s):
NameTypeDescription
firstRowNumberThe first row to include. Because the index starts at 0, a value of 0 returns the first row.
lastRowNumberThe last row to include in the range. Because the index starts at 0, use the value n - 1, in which n equals the actual row number.

 

adding the above changes should fix your issue.

Hi Satheesh,

Thanks for the reply.

I tried this, but it did not helped. I'm still seeing odd number of records on click.

 

Regards.

- Laukik

 

If you have anything else please lmk. 

can you share the updated  code with the above changes? so that it is possible to find where the issue is.