b1serviceflayer 1.0.0 copy "b1serviceflayer: ^1.0.0" to clipboard
b1serviceflayer: ^1.0.0 copied to clipboard

outdated

A starting point for Dart libraries or applications.

A library for Dart developers that makes SAP BusinessOne (B1) Service Layer (SL) programming a lot simpler than using plain http package. B1 is one of the most popular information systems for small and mid sized companies. It runs on Microsoft SQL Server as well as on SAP HANA. SL is available only for the HANA version. The f in the name was inspired by the name sqflite.

Created from templates made available by Stagehand under a BSD-style license.

Usage #

A simple usage example:

import 'dart:convert';
import 'package:b1serviceflayer/b1serviceflayer.dart';

main() async {
  const url = "http://hana93srv:50001/b1s/v1/";
  const user = "manager";
  const pwd ="manager";
  const companyDB ="SBODEMOUS";
  final b1s = B1ServiceLayer(B1Connection(serverUrl: url, companyDB: companyDB, userName: user, password: pwd));
  try {
    print("Logging in ...");
    await b1s.loginAsync().timeout(const Duration(seconds: 10));

    print("Querying activities ...");
    String activitiesJson = await b1s.queryAsync("Activities");
    Map<String, dynamic> activitiesMap = json.decode(activitiesJson);
    List<dynamic> activityList = activitiesMap["value"];
    print('Number of activities ${activityList.length}');
    activityList.forEach((activity){
      print('Activity ${activity["ActivityCode"]} Completed ${activity["Status"]} Notes ${activity["Notes"]} ');
    });

    print("Updating activity ...");
    int activityCodeToComplete = activityList[0]["ActivityCode"];
    activityList[0]["Status"] = -3;
    activityList[0]["Notes"] = "Completed on ${DateTime.now()}";
    await b1s.updateAsync(entityName: "Activities($activityCodeToComplete)",
      entityJSON: json.encode(activityList[0]));

    print("Fetching updated activity ...");
    String activityJson = await b1s.queryAsync("Activities($activityCodeToComplete)");
    Map<String, dynamic> activityMap = json.decode(activityJson);
    print('Activity ${activityMap["ActivityCode"]} Completed ${activityMap["Status"]} Notes ${activityMap["Notes"]} ');

    print("Adding a new activity ...");
    activityJson = await addActivity(b1s, 12);
    activityMap = json.decode(activityJson);
    print('Activity created with code ${activityMap["ActivityCode"]} Notes ${activityMap["Notes"]}');

    print("Deleting the new activity ...");
    activityCodeToComplete = activityMap["ActivityCode"];
    await b1s.deleteAsync(entityName: "Activities($activityCodeToComplete)", errorWhenDoesntExist: true);

    print("Querying activities with newly added activity...");
    activitiesJson = await b1s.queryAsync("Activities");
    activitiesMap = json.decode(activitiesJson);
    activityList = activitiesMap["value"];
    print('Number of activities ${activityList.length}');
    activityList.forEach((activity){
      print('Activity ${activity["ActivityCode"]} Completed ${activity["Status"]} Notes ${activity["Notes"]} ');
    });

    print("Logging out ...");
    await b1s.logoutAsync();
  } on B1Error catch(exception) {
      print("Exception is B1Error (${exception.statusCode}) ${exception.error.message.value} (${exception.error.code}) for Query ${exception.queryUrl}");
      print("Payload ${exception.postBody}");
  } catch(exception,stackTrace) {
    print(exception); print(stackTrace);
  }
}
Future<String> addActivity(B1ServiceLayer b1s, int userId) async {
  final Map<String,dynamic> activityData = {};
  //Subject:-1, ActivityType: -1 /*General*/, Status: -2 /*NotStarted, -3=Completed*/,
  activityData["Notes"] = "A new job to do";
  activityData["ActivityDate"] = "${DateTime.now()}";
  activityData["ActivityTime"] = "08:08:08"; //Activity creation date/time
  activityData["StartDate"] =  "${DateTime(2019,9,7)}"; //Automatically convert Dates and Times to strings in POST/PUT/PATCH
  activityData["StartTime"] = "10:10"; //UTC 0 offset, not the local time :(
  activityData["Details"] = "${DateTime.now()}: more explanation";
  activityData["ActivityType"] = -1;
  activityData["Activity"] = cn_Task;
  activityData["Priority"] = "pr_High";
  activityData["PersonalFlag"] = tNO;
  activityData["DurationType"] = "du_Hours"; 
  activityData["Duration"] = 48.0;
  activityData["HandledBy"] =  userId; //A user number
  return await b1s.createAsync(entityName: "Activities",
    entityJSON: json.encode(activityData));
}

License #

Copyright 2019 Miklos Nemeth (Tiva11)

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

2
likes
0
pub points
21%
popularity

Publisher

unverified uploader

A starting point for Dart libraries or applications.

Homepage

License

unknown (LICENSE)

Dependencies

http, intl, meta

More

Packages that depend on b1serviceflayer