Update Result field in Diagnostics Table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 10:19 AM - edited 09-18-2024 10:20 AM
Hi all,
The requirement is to update the Result field in the Diagnostics Table (custom) once my ouput JSON is recieved as response through integration.
Once, the output field is mapped with the JSON response from integration, the state of the Diagnsotic Record goes to Completed.
I have tried the below BR for the approach, but something is not working.
When: after
Order: 100
Update: Yes
Script:
(function executeRule(current, previous /*null when async*/ ) {
var OutputDiag = current.output;
//gs.log("SREESH - DIAGNOSTICS :: Output Diag is :: " +OutputDiag);
var parser = JSON.parse(OutputDiag);
//gs.log("SREESH - DIAGNOSTICS :: Parsed JSON is :: " +parser);
var outputJSON = parser;
//gs.log("SREESH - DIAGNOSTICS :: POST PARSE is :: " +parser);
var outcomeCode = outputJSON.testRecommendation.outcomeCode;
//gs.log("SREESH - DIAGNOSTICS :: Outcome Code is :: " +outcomeCode);
var outcomeText = outputJSON.testRecommendation.outcomeText;
//gs.log("SREESH - DIAGNOSTICS :: Outcome Text is :: " +outcomeText);
current.result = "Outcome Code: " + outcomeCode + "<br>Outcome Text: " + outcomeText;
//gs.log("SREESH - DIAGNOSTICS :: Updated Output field :: ");
//current.result = "Outcome Code: " + outcomecode1 + "\nOutcome Text: " + outcometext1;
//current.result = "Outcome Code :"+ outcomecode1+"," + "Outcome Text :"+ outcometext1;
current.setWorkflow(false);
current.update();
})(current, previous);
Kindly, help me out here 🙂
Thanks,
Sreesh Surendran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 10:25 AM
Try it ..added condition after parsing if data is available or not
(function executeRule(current, previous /*null when async*/ ) {
try {
var OutputDiag = current.output;
// Log the raw output for debugging
gs.log("SREESH - DIAGNOSTICS :: Output Diag is :: " + OutputDiag);
// Parse the JSON response
var parser = JSON.parse(OutputDiag);
gs.log("SREESH - DIAGNOSTICS :: Parsed JSON is :: " + JSON.stringify(parser));
// Check if testRecommendation exists
if (parser.testRecommendation) {
var outcomeCode = parser.testRecommendation.outcomeCode || "N/A";
var outcomeText = parser.testRecommendation.outcomeText || "N/A";
current.result = "Outcome Code: " + outcomeCode + "<br>Outcome Text: " + outcomeText;
gs.log("SREESH - DIAGNOSTICS :: Updated Output field: " + current.result);
} else {
gs.warn("SREESH - DIAGNOSTICS :: testRecommendation not found in JSON response.");
}
// Set the record state to completed
current.state = "Completed"; // Ensure you have the correct state value
current.setWorkflow(false);
current.update();
} catch (error) {
gs.error("SREESH - DIAGNOSTICS :: Error occurred: " + error.message);
}
})(current, previous);