【Publisher】Thinking about invisible ways of tokens

I will try to solve the problem of the token being visible left as an issue in the previous post [【Publisher】Try executing the scheduled task on Sharperlight instance B from Sharperlight instance A](https://qiita.com/Miki_Yokohata/items/1ffa7755a1637fb46f07)

Instead of triggering the scheduled task in client-side JavaScript, use the server-side method of triggering the scheduled task so that you don't have to use tokens on the client side.
To achieve that, I have another published report with a function defined to execute the scheduled task, and call it from the client-side JavaScript.
When the report is called, the functions defined in the report query are executed and triggering the task on the server side.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/f8f9e133-8005-7c77-3e30-119357f3aa4e.png)
## Preparing report for task launch ##
Create public reports that trigger tasks. When this report is called using the Sharperlight service, the query defined within it will be executed and the desired task will be triggered. Since this is the side that calls the task, it is created on the Sharperlight instance A side.
Launch Sharperlight Publisher.
Start creating a new published report with the `New` button.
Fill in the **Code**, **Group** and **Title** and start building your query with the `Edit Query` button.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/040c7e10-5bb4-3164-aa2b-b43a61ca895a.png)
Since we only need to execute a task, the query result only needs to be one row, so let's set the `Product` to **System**, the `Table` to **User Accounts**, and the `Mode` to the default value of **CU**.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/0e4fec8e-4999-d357-a08e-8743228d6d4b.png)
Define task trigger using an expression for output item.
Define the **Service Name**, **Token**, and **Task Name** of Sharperlight instance B as constants in the Sharperlight system properties. Create trigger by referencing them.
Let's create it with 4 output items.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/c546dc74-4198-1601-0f12-badf2c53fd43.png)
**Service Name:** 
Get the service name of Sharperlight instance B defined in System Properties of Sharperlight instance A.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/3a3219ae-1241-24eb-35f8-96b0b1b14ffd.png)
**Task Name:**
Defines the name of the task to be executed.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/1fad1695-8a11-bddf-588b-87d6d2e1db04.png)
**Token:**
Get the token for Sharperlight instance B defined in System Properties of Sharperlight instance A.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/25e53ede-3e10-9e58-91ec-76105d2c77a4.png)
**Trigger:**
Trigger of the task. Define the launch function by referencing the above items using control tags.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/b5ee876c-0def-be46-eedf-1626d6881ede.png)
The trigger is now complete. you save. Running a query with the query preview feature actually kicks off the task. You can check the operation if you want.
## Editting Validation Report ##
Now, let's edit the verification report created in the previous article (the token was completely exposed).
Instead of running the task launch function in JS, we just want to call the report created above to launch the task.
By doing so, the task launch function defined in the report's query for starting the task will work at the server side.
To do so, use the command `DataSource` of the Sharperlight service.
A report called using the 'DataSource' command will not be displayed as a normal report, but will instead execute the contained query and return the resulting data set in JSON format to the client side.
This time, it's OK if the defined query is executed on the server side, so the task will be started, and the returned query result will be ignored.
Change this part of the previous JS code.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/acda13e9-6875-a8fb-5ec0-d302b416d3a8.png)
This is what it looks like here. You can see that the `DataSource` command is used to call the report for launching the task.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/fc374cd5-15a8-b657-ded9-e8cfa4f30d95.png)
Set this new code in the custom HTML option of the report for verification and save it.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/fd41bdd2-c167-c3ad-0e50-9bf178016709.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/e05c61c1-5534-ea9f-574d-f65e400d9f49.png)
## Verification ##
Start the services of Sharperlight instances A and B.
View the validation report in your browser.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/fd510a9e-8b78-8b1a-26bc-30c3efb7a20f.png)
Open the definition of the Sharperlight scheduled task to be executed and keep the History tab visible.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/ae7ccb5d-8c11-5790-ab12-49afdd489b4b.png)
Click the `Execute Task` button in the verification report. Now go to the history tab of the task and view the history with the `Refresh` icon.
Shows the history of tasks triggered by button clicks.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/bafb8563-fffa-2824-b293-6b9fb250acd5.png)
Try opening the debugger against the report for validation. You can't see the token this time.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/c0d299cd-3a5e-9e0d-6c71-3cf8777829dd.png)

Thank you.