1

I am trying very hard to detect any problem in the following application. There is not any syntax error. However, executing the transaction gives the following error:

Error: Expected a Resource or Concept.

The script file is:

function secondSemesterReportCard(reportCard){
    var factory = getFactory();
    var NS =  'org.studentrecord.record';
    var NS2 = 'org.studentrecord.reportcard'

    return getAssetRegistry('org.studentrecord.record.Record').then(function(tempRecordRegistry){
        return tempRecordRegistry.get(reportCard.studentDetails.registrationNumber);
    }).then(function(tempRecord){
        return tempRecord.secondSemesterReportId;
    }).then(function(tempArray){
        if(tempArray!= null && tempArray.lenght>0){
            var ssReportCard = factory.newResource(NS2, 'SecondSemesterReportCard', reportCard.reportId );
            var tempMarks = factory.newConcept(NS2, 'SecondSemesterMarks');
            tempMarks.SubjectII = reportCard.SecondSemesterMarks.SubjectII;
            tempMarks.SubjectIII = reportCard.SecondSemesterMarks.SubjectIII;

            ssReportCard.secondSemesterMarks = tempMarks;
            ssReportCard.result = reportCard.result;

            var tempDetails = factory.newConcept(NS2, 'StudentDetails');
            tempDetails.registrationNumber = reportCard.studentDetails.registrationNumber;
            tempDetails.firstName = reportCard.studentDetails.firstName;
            tempDetails.lastName = reportCard.studentDetails.lastName;
            tempDetails.faculty = reportCard.studentDetails.faculty;
            tempDetails.enrolledCollege = reportCard.studentDetails.enrolledCollege;

            ssReportCard.studentDetails = tempDetails;

            var tempRelationship = factory.newRelationship(NS,'Record',reportCard.studentDetails.registrationNumber);
            ssReportCard.record = tempRelationship;

             return ssReportCard;
        }
    }).then(function(ssReportCard){
            var recordRegistry={};
            return getAssetRegistry('org.studentrecord.reportcard.SecondSemesterReportCard').then(function(tempRecordRegistry){
                return tempRecordRegistry.add(ssReportCard);
            })
            .then(function(){
                return getAssetRegistry('org.studentrecord.record.Record');
            })
            .then(function(tempRecordRegistry){
                recordRegistry = tempRecordRegistry;
                return tempRecordRegistry.get(reportCard.studentDetails.registrationNumber);
            }).then(function(tempRecord){
                if(tempRecord.secondSemesterReportId){
                    tempRecord.secondSemesterReportId.push(reportCard.reportId);
                }else{
                    var tempArray = [reportCard.reportId];
                    tempRecord.secondSemesterReportId = tempArray;
                }

                return recordRegistry.update(tempRecord);                           
            });
        });
}
pushkin
  • 9,575
  • 15
  • 51
  • 95
  • Telling us more details would be helpful, for instance, what line does the error occur on when executing? – Shelby115 Jun 20 '18 at 16:53
  • The model file would help too. – R Thatcher Jun 21 '18 at 08:35
  • these Stack Overflow answers -> https://stackoverflow.com/questions/48879731/getting-error-expected-a-resource-or-concept-have-checked-older-posts-too-but-i and https://stackoverflow.com/questions/48724746/error-expected-a-resource-or-concept may help you as guidelines to similar coding issues – Paul O'Mahony Jun 22 '18 at 09:05
  • I suspect one major issue is you've got a typo - currently written (javascript) as`tempArray.lenght` - well that's not going to > 0 :-) and that condition check may be why part 2 doesn't get populated. – Paul O'Mahony Jun 22 '18 at 14:08
  • Thanks @PaulO'Mahony. That resolved the issue. – Kaushal Poudel Jun 22 '18 at 14:26

0 Answers0