0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Publisher】Writeback using Restful service

Posted at

This time, we will use the Restful service of Sharperlight to create a data write process in JavaScript.
Let's start from scratch.

Preparing the database

Create a new database in Microsoft SQL Server.

New database

Create a new database with Microsoft SQL Management Studio as follows: Shall we call it QiitaTopic
image.png
image.png

Creating table

Prepare a table for storing data. Create by script.

CREATE TABLE [dbo].[Sales_Items](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[code] [varchar](512) NOT NULL,
	[name] [varchar](1024) NOT NULL,
	[qty] [int] NOT NULL,
	[amount] [decimal](18,0) NOT NULL,
	[date] [datetime] NOT NULL
 CONSTRAINT [PK_Sales_Items_ID] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

image.png

Creating a data model

Launch Studio from the Sharperlight application menu.
Click the new icon to get ready to connect to the database you just created.
image.png
Set Description, Unique Code, Target Platforms and press the OK button.
image.png
A dialog for entering the connection details to the database will be displayed, so enter the correct connection information. You can check the connection with the Test button. I used Windows authentication this time, but you can also use SQL server authentication.
If you can confirm that the connection is done correctly with the Test button, save it with the OK button.
image.png
A message appears prompting you to load the database schema information. Click the Yes button to proceed.
image.png
The Import Objects dialog will appear. Keep the default settings and press the Get Tables button (green button).
image.png
The schema information of the database is displayed in a tree format, so confirm that all are checked and proceed with the OK button.
image.png
A message Created 1 new Tables will be displayed, so click the OK button to proceed.
image.png
The table tree will be displayed on the left, so open the Other folder and double-click the displayed table. A list of fields appears in the middle area. This is the initial state with the schema information loaded.
The table is also in the Other folder. This state is reflected in the display of the table search dialog of the Query Builder. The meaning of the Other folder is unknown, so consider renaming it or moving the table to the root folder.
Move it to the root folder, i.e. the Table Display folder, then delete the Other folder.
Select the Table Display folder and select Move Tables from the right-click menu.
image.png
Since the table list is displayed, put a check mark and press the OK button.
image.png
After confirming that the table has been moved, select the Other folder and select Delete Folder from the right-click menu.
image.png
A confirmation message will be displayed, so select the Yes button.
image.png
The Other folder will be deleted and you will have a clean state like this.
image.png
Then set the table to data writable. Sharperlight basically prohibits writing data.
This time we want to write data to this table, so we give this table Writeback permission.
When you select the table, the table properties list will appear in the right pane. Locate the Allow Table Writeback property and set it to True.
image.png
This completes the creation of the data model. Select Exit from the File menu. A message prompting you to save will be displayed, so save with the Yes button.
image.png
A note about where to save the data model will be displayed, so click the OK button to proceed.
image.png
The file explorer will be displayed, so leave the destination as it is and click the Save button.
image.png
The data model is now ready.

Connecting database and data model

Launch Client Setup from the Sharperlight application menu.
Set the database connection information for the target data model QiitaTopic and check the connection with the test connection button.
image.png
Sharperlight can now talk to the database through the data model.
Then enable the service. The settings are as shown below. The service code is used as part of the service's URL.
Save with the OK button.
image.png

Preparing data writing UI and backend code

In this article, the data written is a fixed value, and only the Save button etc. is placed on the web page. Then we will see how to create writeback using RESTful services.

Starting RESTful service

Now let's start the service. Services can be started from the Sharperlight application menu or from Windows Services.
image.png
image.png

Viewing the Service Index Page

After the service starts, display the index page. Use the URL below.

http://{your server name is here}/mdService1Rest/Index

image.png

Getting JavaScript template for writeback

Templates are accessed from the index page under Writeback -> Metadata. Enter the code QTX of the data model created earlier in the Product Code filter and press the send button.
image.png
A list of tables will be displayed immediately below, so select the target table name Sales Items. Various URLs and JavaScript templates are displayed on the right.
Copy JavaScript POST Simple or JavaScript POST Full to your clipboard.
Create a new report in Publisher and check Header on the Options tab.
Launch the editor with the Edit button and paste the template previously copied to the clipboard.
image.png
image.png
And since the writeback data is a fixed value, set the test data here in the template code.
image.png
Save the template code with the OK button.
Create a query for the Sales Items table with the Edit Query button.
image.png
After creating the query, enter the report Group name and Code and save it.
image.png
Select View Report from the right-click menu to view the report in a browser.
image.png
A page like this was displayed.
When you press the SAVE button, the test data set earlier will be written to the database.
If the writeback is finished successfully, the SAVE button will turn green like this.
image.png
Try refreshing the report or querying the Sales_Items table in Microsoft SQL Management Studio to see if the data is actually being written.
image.png
image.png

In this way, Sharperlight is not just a reporting tool, but by using it in common with JavaScript, HTML, etc., various solutions can be created without much effort, which is very interesting.

Thank you for reading this article.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?