Git Product home page Git Product logo

servicemanager-table-builder's Introduction

Currently unmaintained since I have moved from Microfocus Service Manager to ServiceNow - Sorry guys!

Table of Contents

Installation

Just create a new ScriptLibrary for each file and copy the file content inside the new created ScriptLibrary. Currently there is no plan to deliver a unload file.

Supported Databases

  • MSSQL - tested with SM 9.52 and SM9.60
  • Postgres - tested with ITSMA ( SM9.52 )

Make a table

To create a new dbdict table, you have to use the make method.

var tableBuilder = system.library.tableBuilder.getClass();


var schema = new tableBuilder();

schema.make('complextable', function(builder) {

	/**
	 * Allowed methods are:
	 * * all methods to add a field
	 * * all methods to add a key
	 */

});

Update a table

To update a existing dbdict table, you have to use the modify method.

var tableBuilder = system.library.tableBuilder.getClass();


var schema = new tableBuilder();

schema.modify('complextable', function(builder) {

	/**
	 * Allowed methods are:
	 * * all methods to add a field
	 * * all methods to add a key
	 * * rename a field
	 */

});

Available Fields

Type SM Type
Number 1
Character 2
Date/Time 3
Logical 4
Array 8
Structure 9
Expression 11

Available Keys

  • Unique
  • Primary
  • No Nulls
  • No Duplicates
  • Nulls & Duplicates

Todos

  • [] more documentation for each field
  • [] Add more options

Fields

Number

builder.addNumber('fieldname');

Character

builder.addCharacter('fieldname');

Date/Time

builder.addDatetime('fieldname');

Logical

builder.addLogical('fieldname');

Array

builder.addArray('fieldname', function(item) {
	//all field types are allowed
});

Available Aliases

Array of Number
builder.addArrayOfNumber('fieldname');

Array of Character
builder.addArrayOfCharacter('fieldname');

Array of Date/Time
builder.addArrayOfDatetime('fieldname');

Array of Logical
builder.addArrayOfLogical('fieldname');

Structure

builder.addStructure("filter", function(item) {
	item.addCharacter("filter.sql");
});

Expression

builder.addExpression('fieldname');

Modify Methods

renameField

Currently, the rename works only for simple fields (number, character, date/time, logical).

Rename the field, but keep the SQL Name

builder.renameField('is_active', 'isActive');

Rename the field and update the SQL Name.

builder.renameField('is_active', 'isActive', true);

setLength

Updates the sql length of a field. The method uses the information from the sqldbinfo table to determines if the current field has the Get Size option.

builder.setLength('brief.description', 500);

Field Options

Set SQL Type

For common fields, you can change field SQL Type.

builder.addCharacter("textfield").setSqlType("NVARCHAR(100)");

Set SQL Field Name

Overwrites the default sql field name with the defined value.

builder.addCharacter("textfield").setSqlName("AWESOMETEXTFIELD");

Set SQL Table

If you want, you can move a field to another table alias (e.g. from M1 to M2).

❗ All following fields will be attached to M2. If you want only one field in a new table, add the field at the end of your definition or add .setSqlTable("M1") to the next field.

This is an HPSM problem - I have tested it with the dbdidct utilities and the result was the same!

builder.addCharacter("textfield").setSqlTable("M2");

Keys

Unique

builder.addUniqueKey(['fieldname']);

Primary

builder.addPrimaryKey(['fieldname']);

No Null

builder.addNoNullKey(['fieldname']);

No Duplicates

builder.addNoDuplicateKey(['fieldname']);

Nulls & Duplicates

builder.addNullDuplicateKey(['fieldname']);

Helpers

Sysmod Fields

Instead of

builder.addCharacter('sysmoduser');
builder.addDatetime('sysmodtime');
builder.addNumber('sysmodcount');

in your definition, you can use this:

builder.withSysmodFields();

Examples

Simple create example

var tableBuilder = system.library.tableBuilder.getClass();


var schema = new tableBuilder();

schema.make('simpletable', function(builder) {
	
	builder.addNumber('id');
	builder.addLogical('is_active');
	builder.addCharacter('sysmoduser');
	builder.addDatetime('sysmodtime');
	builder.addNumber('sysmodcount');
	
	builder.addUniqueKey(['id']);
});

Expected result after running the code:

You should see a new entry in your Messages with something like:

Table simpletable has been created successfully.

Complexe create example

var tableBuilder = system.library.tableBuilder.getClass();


var schema = new tableBuilder();

schema.make('complextable', function(builder) {
	
	builder.addNumber('id');
	builder.addLogical('is_active');
	builder.addCharacter('brief.description');

	builder.addArray("longdescription", function(item) {
		item.addCharacter("longdescription");
	});
	
	builder.addStructure("filter", function(item) {
		item.addCharacter("filter.sql");
	});
	
	builder.addArray("rule", function(item) {
		item.addStructure("rule", function(subitem) {
			subitem.addNumber("ruleId");
		});
	});

	builder.withSysmodFields();
	
	builder.addUniqueKey(['id']);

});

Modify table example

var tableBuilder = system.library.tableBuilder.getClass();


var schema = new tableBuilder();

schema.modify('complextable', function(builder) {
	//add a new field to the existing table
	builder.addNumber('reference.id');
	builder.renameField('is_active', 'isActive', true);	
	builder.setLength('brief.description', 500);	
});

Expected result after running the code:

You should see a new entry in your Messages with something like:

Table complextable has been created successfully.

Credits

Special thanks goes to:

  • yim OHG - My old company ❤️ My first version was built there and this version includes also some parts from Version 1 (see inline mentions ;) )
  • ironboy - He is the creator of the awesome classier package. I had to modify the class a bit to make it work inside the HPSM.

servicemanager-table-builder's People

Contributors

noxify avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

servicemanager-table-builder's Issues

add Array of Date/Time alias

To simplify the definition, it would be good to have an alias like addDatetimeArray.
It's just an alias for

builder.addArray("fieldname", {}, function(item) {
	item.addDatetime("fieldname");
});

add possibility to modify an existing table

New method modify is available and you can do the following

  • Add new fields to the table
  • Modify existing fields (as good as possible ;) )
  • "delete" an field (means here, remove the SQL field and map the dbdict field to the null table)

add Array of Number alias

To simplify the definition, it would be good to have an alias like addNumberArray.
It's just an alias for

builder.addArray("fieldname", {}, function(item) {
	item.addNumber("fieldname");
});

add Array of Character alias

To simplify the definition, it would be good to have an alias like addCharacterArray.
It's just an alias for

builder.addArray("fieldname", {}, function(item) {
	item.addCharacter("fieldname");
});

add Array of Logical alias

To simplify the definition, it would be good to have an alias like addLogicalArray.
It's just an alias for

builder.addArray("fieldname", {}, function(item) {
	item.addLogical("fieldname");
});

Sysmod* Field alias

Add a new field addSysmod to the builder which generates the following fields:

  • sysmodtime (date/time)
  • sysmodcount (number)
  • sysmoduser (character)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.