- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 12:45 AM
Hi All, Getting below error while printing log statements.
Below is the code I've written:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 12:54 AM
As per the screenshot, this is not an error, you have parsed the JSON thats why you get the data as JSON object
Please do it as follows:
var opportunities = parsedData.opportunitiesData;
opportunities = JSON.stringify(opportunities);
gs.info(opportunities);
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 01:04 AM
Hi @peri sravani1 ,
The Output is in JSON format in order to view it you can stringify it as mentioned by Prince above.
You can write this line instead
gs.info("test line 40 "+JSON.stringify(opportunities));
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 06:11 AM
Hi @peri sravani1 ,
I presume u have written a scripted Rest API for this. You can just do a GlideRecord query to insert the data & while doing a GlideRecord query u can verify if the data exists if no then initialize if yes then update/ignore based on your requirement.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 10:08 AM
I'm updating the records but they are not getting updated.
oppo.update();
This will work in action part script thing right Danish!?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 10:11 AM
Hi @peri sravani1 ,
Possible to share ur script.will be bit easier to find the issue if any.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 10:27 AM
(function execute(inputs, outputs) {
// ... code ...
try {
var r = new sn_ws.RESTMessageV2('x_xxxx_xxxx_xxxxx.SAM.gov Data Import', 'Get Opportunities Public API');
r.setStringParameterNoEscape('samgov_get_postedfrom', gs.getProperty('x_xxxx_xxxx_xxxxx.samgov_get_postedfrom'));
r.setStringParameterNoEscape('samgov_get_postedto', gs.getProperty('x_xxxx_xxxx_xxxxx.samgov_get_postedto'));
r.setStringParameterNoEscape('offset', 0);
gs.info("test line no.11");
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var parsedResponse = JSON.parse(responseBody);
gs.info("test line no.18");
var totalSize = parsedResponse.totalRecords;
gs.info("test line no.20");
gs.info("######test line 22 "+totalSize);
var baseOffset = 100;
var totalOpportunities = [];
for(var j=0;j < Math.ceil(totalSize/baseOffset); j++ ){
let r = new sn_ws.RESTMessageV2('x_xxxx_xxxx_xxxxx.SAM.gov Data Import', 'Get Opportunities Public API');
r.setStringParameterNoEscape('samgov_get_postedfrom', gs.getProperty('x_xxxx_xxxx_xxxxx.samgov_get_postedfrom'));
r.setStringParameterNoEscape('samgov_get_postedto', gs.getProperty('x_xxxx_xxxx_xxxxx.samgov_get_postedto'));
r.setStringParameterNoEscape('offset', (baseOffset*j));
let response = r.execute();
let responseBody = response.getBody();
let httpStatus = response.getStatusCode();
let parsedData = JSON.parse(responseBody);
let opportunities = parsedData.opportunitiesData;
var a = JSON.stringify(opportunities.length);
gs.info("test line 40 "+a);
totalOpportunities = [...totalOpportunities,...opportunities];
}
gs.info("#######test line 44 "+totalOpportunities.length);
var specialNotices = 0;
var updateCount = 0;
var insertCount = 0;
// start bulk insert
for(var i=0;i<totalOpportunities.length;i++) {
var oppo = new GlideRecord("x_xxxx_xxxx_xxxxx_opportunity");
oppo.setValue("noticeid", totalOpportunities[i].noticeId);
oppo.setValue("title", totalOpportunities[i].title);
oppo.setValue("solicitation_number", totalOpportunities[i].solicitationNumber);
oppo.setValue("posted_date", totalOpportunities[i].postedDate);
oppo.setValue("type", totalOpportunities[i].type);
oppo.setValue("base_type", totalOpportunities[i].baseType);
oppo.setValue("archive_type", totalOpportunities[i].archiveType);
oppo.setValue("archive_date", totalOpportunities[i].archiveDate);
oppo.setValue("response_deadline", totalOpportunities[i].responseDeadLine);
oppo.setValue("u_naics_code", totalOpportunities[i].naicsCode);
oppo.setValue("classification_code", totalOpportunities[i].classificationCode);
oppo.setValue("active", totalOpportunities[i].active);
oppo.setValue("organization_type", totalOpportunities[i].organizationType);
//oppo.setValue("u_naics_code", parsedData.opportunitiesData[i].placeOfPerformance);
//set any other values
if(totalOpportunities[i].solicitationNumber==''){
specialNotices = specialNotices + 1;
oppo.insert();
}
else{
var oppoList = new GlideRecord('x_xxxx_xxxx_xxxxx_opportunity');
oppoList.addQuery('solicitation_number', totalOpportunities[i].solicitationNumber);
oppoList.query();
if(!oppoList.hasNext()) {
oppo.insert();
insertCount = insertCount + 1;
}
else{
if(totalOpportunities[i].solicitationNumber == '36C25924Q0044'){
gs.info('Hii123'+totalOpportunities[i].title);
oppo.setValue("title", totalOpportunities[i].title);
oppo.update();
var b = oppo.getValue("title");
gs.info('Hii123'+b);
}
oppo.update();
updateCount = updateCount + 1;
}
}
}
gs.info("####insertss"+insertCount+"$$$$$updatess"+updateCount+"%%%%%specialNoticess"+specialNotices);
}
catch(ex) {
var message = ex.message;
}
})(inputs, outputs);
This is the code I've used Danish...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 01:27 AM
Hi @Danish Bhairag2
This is the code I'm using.