Support Portal

for ProcessRobot and WinAutomation

Start a new topic
Answered

Variables not replaced, but why

Hey,


I'm currently working on a bot, which is accessing an API. I tested the API request in Postman and it's working.

First of all here is what the bot is doing step by step:

1. set variables

2. User input JSON-File (incl WinAutomation Variable names)

3. Checking JSON for errors

4. Read Text from file

5. Replacing newline with tab (to create an oneliner)

6. Get Temporary File

7. Rename Temp File to HTML

8. Open Temp File in Browser

9. Check JSON for parameter

10. Invoke Web Service (fail due to not replaced variables)


In this JSON File are multiple objects inside and the API will create a new ressource for each object. So I inserted the correct variables in one object and winautomation variables in the other. The first one was successful, while the winautomation part failed due to '%' in the API request, but why isn't it replaced?


Best Answer

Hello Nico,


Thank you for your reply.


The issue here is that you are reading the whole body from a text file, so WinAutomaton/ProcessRobot interprets the whole body as simple text, thus not translating the variables into their actual values.


What you could do is the following.


  • Read the JSON from the file and store it in a variable, let's call it %JSON_text%.
  • Use the "Replace Text" action, from the "Text Actions" group of actions, replace the variables in the JSON body and store the changes in the same %JSON_text% variable, as shown in the screenshot below.
  • Place %JSON_text% in the body of the "Invoke Web Service" action.

I hope the above proves useful.

image



ADMIN

Hello Nico,


Please try escaping the '%' character by using a backslash '\' before it.


1 person likes this

When I escape the '%' I get Unrecognized character escape '%' returned by the API so the variable still isn't replaced before invoking

ADMIN

Hello Nico,


Thank you for your reply.


If possible, please share with us the API request.


1 person likes this

as it's company internal, I can't, but I can give the documentation of it


https://docs.atlassian.com/software/jira/docs/api/REST/7.13.0/#api/2/issue-createIssues

ADMIN

Hello Nico,


Thank you for your reply.


Please, if possible, share with us parts of the body, or anywhere else in the API request, where you are using variables, so as to be able to investigate the issue further.


Please note, that as a workaround, you can place the entire body of the request in a single variable and place that variable in the action's "Request Body" field.


We will be looking forward to your response.


1 person likes this

I replaced all ID's names and texts with random ones.

This JSON is written in a file. WinAutomation reads this file and stores it in a variable, which is used in the invoke. The first issues, where the id's aren't variables works fine. The second one with the variables throws errors due to the '%'


 

{
    "issueUpdates": [
        {
			"update": {},
			"fields": {
				"project": {
					"id": "23742"
				},
				"summary": "First Issue",
				"issuetype": {
					"id": "7"
				},
				"assignee": {
					"name": null
				},
				"reporter": {
					"name": "name"
				},
				"timetracking": {
					"originalEstimate": "10",
					"remainingEstimate": "10"
				},
				"description": "some text",
				"duedate": "2019-01-31",
				"components": [
					{
						"id": "34634"
					}
				],
				"customfield_10710": "EPIC-141"
			}
        },
        {
			"update": {},
			"fields": {
				"project": {
					"id": "%projectID%"
				},
				"summary": "Second Issue",
				"issuetype": {
					"id": "7"
				},
				"assignee": {
					"name": null
				},
				"reporter": {
					"name": "%leadUser%"
				},
				"timetracking": {
					"originalEstimate": "10",
					"remainingEstimate": "10"
				},
				"description": "some more text",
				"duedate": "2019-02-18",
				"components": [
					{
						"id": "%componentID%"
					}
				],
				"customfield_10710": "%epicKey%"
			}
        }
    ]
}

 

ADMIN
Answer

Hello Nico,


Thank you for your reply.


The issue here is that you are reading the whole body from a text file, so WinAutomaton/ProcessRobot interprets the whole body as simple text, thus not translating the variables into their actual values.


What you could do is the following.


  • Read the JSON from the file and store it in a variable, let's call it %JSON_text%.
  • Use the "Replace Text" action, from the "Text Actions" group of actions, replace the variables in the JSON body and store the changes in the same %JSON_text% variable, as shown in the screenshot below.
  • Place %JSON_text% in the body of the "Invoke Web Service" action.

I hope the above proves useful.

image



1 person likes this

 Hello George,


I just tried your idea and it worked. I'm so happy right now! Thank you very much, you saved me a lot of time!


Greets,

Nico

ADMIN

I'm glad I could help Nico.


Best wishes for a lovely week!


1 person likes this
Login or Signup to post a comment