Forum Discussion

omair's avatar
omair
Contributor
9 years ago

Script snap with ultra pipelines: original property mapping to doc which is modified

Hi,

I have a question regarding this statement from the SnapLogic documentation on Ultra Pipeline tasks (https://docs-snaplogic.atlassian.net/wiki/display/SD/Ultra+Pipeline+Tasks):

Script and Execute Script Snaps need you to pass the original document to the ‘write()’ method for the output view.

I am using a script snap in a pipeline to modify the original document to move some properties around (thereby changing the original document). I am wrapping my original document in a wrapper and putting it in the original property as demonstrated in the sample Script snap. However, “original” contains my modified doc. Will this be a problem if I try to use Ultra?

A snippet from my Script snap is included below:

execute : function () {
        this.log.info("Executing Transform Script");
        while (this.input.hasNext()) {
            try{
                // Read the next document, wrap it in a map and write out the wrapper
                var doc = this.input.next();
                var wrapper = new java.util.HashMap();
                wrapper.put("original", doc.clone());
                wrapper.put("integrationMessage", doc["integrationMessage"]);
                
                var studentGradesWrapper = doc["integrationMessage"]["body"]["gradingSheetInfo"]["gradingSheet"]["studentGrades"];
                var supplementalInfosWrapper = doc["integrationMessage"]["body"]["gradingSheetInfo"]["supplementalInfos"];
                ensureArray(studentGradesWrapper,"studentGrade");
                ensureArray(supplementalInfosWrapper, "supplementalInfo");
                var studentIdsToCslwIdsMap = new java.util.HashMap();
                supplementalInfosWrapper["supplementalInfo"].forEach(
                    function(supplementalInfo) {
                        studentIdsToCslwIdsMap.put(supplementalInfo["studentId"], supplementalInfo["coursesectionLW"]["objectId"]);
                    }
                );
                studentGradesWrapper["studentGrade"].forEach(
                    function(studentGrade) {
                        studentGrade.put("snapLogicCourseSectionLWId",studentIdsToCslwIdsMap.get(studentGrade["student"]["objectId"]));
                    }
                );

                this.output.write(doc, wrapper);
            }
            catch(err) {
                var wrapper = new java.util.HashMap();
                wrapper.put("errorMsg", err);
                this.log.error(err);
                this.error.write(wrapper);
            }
        }
    }