Refresh the token from API Integration and retrieve the records in specified bunch to POST and Get
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 08:33 AM - edited 07-25-2023 08:36 AM
Hi Experts,
I'm working on Integration requirement, below is the script include code,
from line no. 27 I'm getting the "PO" numbers from the table records and passing those into the POST method JSON payload in line no.32.
as of now I'm able to pass 10 records PO numbers one time but the requirement is each time I need to pass the 10 PO numbers, after those PO numbers detail got updated in the table, code should pick the next 10 PO numbers and it should continue the above logic.
With the above script , How can I Loop this for multiple calls..
and in line no. 16 I'm getting the token which is valid only for one hour, after one hour code should refresh the token and pass new token in line no. 31, how can I refresh the token.
after refreshing the token PO numbers update should start from where the last token expired
I have attached the script,
Thanks in advance,
Chaithanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 04:19 PM
Hi, based on details you have provided, in your while loop I would increment a counter
for each loop/count push your data into your integration array or object as required,
then on the 10 count trigger your integration, reset the array\object and continue through your loop
Perhaps something like this (background script for PDI)
var myCount = 1;
var myResult = [];
var someLoop = new GlideRecord('incident');
someLoop.query();
while(someLoop.next()) {
//update your integration data array or object
myResult.push(someLoop.number.toString());
if(myCount % 10 == 0){ //modulo result if the remander is 0 the counter is an increment of 10
//Trigger an integration
gs.info("count " + myCount + " | " + myResult.toString());
//reset your integration data array or object
myResult = [];
}
myCount ++
}
Regarding your token, you could either refresh your token each time the process runs IE before the while loop,
Or check each integration returns correct result and if it fails dure to expired token refresh token and resend the integration message.
Another (more complex) option is to manage your token externally to this process, using scheduled jobs to validate that it is current and to refresh if required.