Skip to main content

Hi,

 

I am using the websocketSender transformer to stream some data; when I am using the template in the data to transmit as below:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : "FME Rocks"

 

}

 

I have no issues; however when replacing the "FME Rocks" with the attribute name, nothing happens. For example, if I have an attribute named "id", here is what I do:

{

 

"ws_op" : "send",

 

"ws_msg" : fme_get_attribute("id")

 

}

I don't get any errorr, it is just that data is not transmitted compared to the first case.

Any pointers would be much appreciated.

Thanks.

Lyes

 

 

 

Hi @gisinnovationsb,

 

 

you can try this:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : ("id")

 

}

 

 

or this:

 

 

{

 

ws_op: 'send',

 

ws_msg: '@Value(id)'

 

}

 

 

HTH

Andrea


Hi, I created the string using the AttributeCreator then assigned the created string to Data to Transmit. The result was something like this:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : @Value(id)

 

}

 

I can now transmit data successfully from one workspace to another.


Hi @gisinnovationsb,

 

 

you can try this:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : ("id")

 

}

 

 

or this:

 

 

{

 

ws_op: 'send',

 

ws_msg: '@Value(id)'

 

}

 

 

HTH

Andrea

Hi @afavaccio both didn't work. I found the solution please refer to my reply and thanks for the help.


Hi, I created the string using the AttributeCreator then assigned the created string to Data to Transmit. The result was something like this:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : @Value(id)

 

}

 

I can now transmit data successfully from one workspace to another.

Haha, gosh very sensitive to the syntax. Not what I'm used to with FME. Thanks for sharing your results.


Haha, gosh very sensitive to the syntax. Not what I'm used to with FME. Thanks for sharing your results.

Hi Matt, I will accept your comment as the response ;)


Hi, I created the string using the AttributeCreator then assigned the created string to Data to Transmit. The result was something like this:

 

 

   {

 

       "ws_op"  : "send",

 

        "ws_msg" : @Value(id)

 

    }

 

I can now transmit data successfully from one workspace to another.

I think the data to transmit should be a valid JSON text.

If id was a numeric value - e.g. 100, your expression would be a valid JSON. 

{
"ws_op" : "send",
"ws_msg" : 100
}

 

However, if id was a non-numeric value - e.g. ABC, the expression wouldn't be a valid JSON.

{
"ws_op" : "send",
"ws_msg" : ABC
}

 

In the case, the id should be quoted with double quotations, as in.

{
"ws_op" : "send",
"ws_msg" : "ABC"
}

Hi, I created the string using the AttributeCreator then assigned the created string to Data to Transmit. The result was something like this:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : @Value(id)

 

}

 

I can now transmit data successfully from one workspace to another.

I had a similar issue. The explanation that I got in https://knowledge.safe.com/questions/98505/send-json-via-websocket.html from @denniswilhelm (which I've verified too) is: "fme_get_attribute automatically escapes " to \\" which isn't done by the @Value command. In a JSONTemplater you can also use fme:get-json-attribute("yourAttributeName") to explicitly load insert valid JSON values."

 

Hence the difference between the two, seemingly, identical ways to get data from the attribute.


Reply