Getting error ""resp" is not defined." while running code in background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 07:17 AM
I Am trying to run below mentioned code in background script but in line no. 3 its showing me error "resp" is not defined.", please suggest how to resolve this.
responseBody = [{"isSuccess":false,"errorMessage":"Agreement: 00000288.0 is not present in Conga","apttus_contract_id":"00000288.0"},{"isSuccess":true,"errorMessage":"","apttus_contract_id":"00006475.0"}];
for(var i in responseBody){
var flag = resp[i].isSuccess;
if(!flag){
resp[i].apttus_contract_id;
gs.info('testing response For True/False');
}
}
- Labels:
-
Connect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 07:20 AM
Try this:
responseBody = [{"isSuccess":false,"errorMessage":"Agreement: 00000288.0 is not present in Conga","apttus_contract_id":"00000288.0"},{"isSuccess":true,"errorMessage":"","apttus_contract_id":"00006475.0"}];
for(var i in responseBody){
var resp= JSON.parse(i);
var flag = resp[i].isSuccess;
if(!flag){
resp[i].apttus_contract_id;
gs.info('testing response For True/False');
}
}
I hope this helps!
If this was helpful, or correct, please be kind and mark the answer appropriately.
Michael Jones - Proud member of the GlideFast Consulting Team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 07:22 AM
Basically you need to turn the JSON payload (each item of your array) into an object to be able to reference it's properties, etc.
I hope this helps!
If this was helpful, or correct, please be kind and mark the answer appropriately.
Michael Jones - Proud member of the GlideFast Consulting Team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 07:27 AM
I added line "var resp= JSON.parse(i);" before line no. 3 and this time i got below error in line no. 4.
Evaluator: com.glide.script.RhinoEcmaError: Cannot read property "isSuccess" from undefined
script : Line(4) column(0)
1: responseBody = [{"isSuccess":false,"errorMessage":"Agreement: 00000288.0 is not present in Conga","apttus_contract_id":"00000288.0"},{"isSuccess":true,"errorMessage":"","apttus_contract_id":"00006475.0"}];
2: for(var i in responseBody){
3: var resp= JSON.parse(i);
==> 4: var flag = resp[i].isSuccess;
5: if(!flag){
6: resp[i].apttus_contract_id;
7: gs.info('testing response For True/False');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 07:40 AM
Interesting - it worked for me, but maybe try this (copy the whole script, please)
responseBody = [{"isSuccess":false,"errorMessage":"Agreement: 00000288.0 is not present in Conga","apttus_contract_id":"00000288.0"},{"isSuccess":true,"errorMessage":"","apttus_contract_id":"00006475.0"}];
for(var i in responseBody){
var resp= JSON.parse(i);
var flag = resp.isSuccess;
if(!flag){
resp.apttus_contract_id;
gs.info('testing response For True/False');
}
}
I hope this helps!
If this was helpful, or correct, please be kind and mark the answer appropriately.
Michael Jones - Proud member of the GlideFast Consulting Team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
