static void testJobAIFDocumentServices(Args _args) { #define.CourseId("AX7-DEVI") #define.CourseName("AX7 Introduction DevelopmentI") #define.Trainer("van Kessel") FOXCourseQueryService service; // Service class (extends with AifDocumentService) FOXCourseDocument document; // Document object (extends with AifDocument) FOXCourseDocument_FoxCourse dataObject; // Data object (extends with AfStronglyTypedDataContainer) String30 id; Map map; AifEntityKey key = new AifEntityKey(); AifEntityKeyList entityKeyList = new AifEntityKeyList(); //Choose the transactiontype AxdEntityAction entityAction = AxdEntityAction::update; str getHashCode(String30 _courseId) { //Hashcode is mandatory for updating AxdBaseRecordInfo recordInfo; FOXCourse foxCourseLoc; str documentHash; Map dataSourceMap = new Map(Types::Integer,Types::Integer); ; select firstOnly name, trainer from foxCourseLoc where foxCourseLoc.Id == _courseId; recordInfo = AxdBaseRecordInfo::newCommon(foxCourseLoc, 1 , dataSourceMap); documentHash = recordInfo.getRecordHash(); return documentHash; } void getDocumentData() { document = new FOXCourseDocument(); document.createFoxCourse(); dataObject = document.parmFoxCourse().addNew(); if (entityAction == AxdEntityAction::update) { //Hashcode is mandatory for update operation dataObject.parm_DocumentHash(getHashCode(#CourseId)); } //Key Id should also given for update //In that case should the given key the same as he orig key // (see validation rule in AxdBase/checkFieldsForUpdate) dataObject.parmId(#CourseId); dataObject.parmName(#CourseName); dataObject.parmTrainer(#Trainer); } ; //Instantiate the service service = FOXCourseQueryService::construct(); //Document if (entityAction == AxdEntityAction::update || entityAction == AxdEntityAction::create) { getDocumentData(); } // Compose the entityKeyList map = new Map(Types::Integer, Types::Container); map.insert(fieldnum(FOXCourse, Id), [#CourseId]); // Compose the keyfield key.parmTableId(tablenum(FOXCourse)); key.parmKeyDataMap(map); entityKeyList.addEntityKey(key); // run the service switch (entityAction) { case AxdEntityAction::create : service.create(document); break; case AxdEntityAction::update : service.update(entityKeyList, document); break; case AxdEntityAction::delete : service.delete(entityKeyList); break; } id = entityKeyList.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(FOXCourse, Id)); info(strfmt("Course %1 is %2d", id, entityAction)); }