How to use Process Tags with c-objects?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use Process Tags with c-objects?

KirkBrooks
I haven't used Process Tabs very much but it is promising.

I use javaScript and jQuery to turn JSON into web pages and web areas. I
thought I'd look at doing this on the 4D side with process tags but I can't
find a clean way to process data from a c-object. All my solutions are
overly involved which makes me think I'm missing something.

Is anyone doing this also? Could you share a few tips on how you make it
work?

Thanks

--
Kirk Brooks
San Francisco, CA
=======================
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to use Process Tags with c-objects?

Lee Hinde
It feels like you'd have to use 4Deval.  But, I think I'd unpack a c_object
with javascript once in the web page.


On Sun, Oct 30, 2016 at 8:38 AM, Kirk Brooks <[hidden email]> wrote:

> I haven't used Process Tabs very much but it is promising.
>
> I use javaScript and jQuery to turn JSON into web pages and web areas. I
> thought I'd look at doing this on the 4D side with process tags but I can't
> find a clean way to process data from a c-object. All my solutions are
> overly involved which makes me think I'm missing something.
>
> Is anyone doing this also? Could you share a few tips on how you make it
> work?
>
> Thanks
>
> --
> Kirk Brooks
> San Francisco, CA
> =======================
>
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to use Process Tags with c-objects?

Douglas von Roeder
Kirk:

The code below is used to populate dynamic variables with data coming in
from SAP via XML:


*C_LONGINT*($index_L)

*For *($index_L;1;*OT_SizeOfArray *
($orderListHandle_L;"$orderDetailObjectNames_AT"))


*     C_TEXT*($objectName_T)

     $objectName_T:=*OT_GetArrayText *
($orderListHandle_L;"$orderDetailObjectNames_AT";$index_L)



     *C_TEXT*($tag_T)

     $tag_T:=*OT_GetArrayText *
($orderListHandle_L;"$orderObjectTagNames_AT";$index_L)


     (*OBJ_GPBN *($objectName_T))->:=*OB Get*($orderHeaderDetail_O;$tag_T;
*Type*(*OBJ_GPBN *($objectName_T)->))


*End for *




The OT_ methods are wrapper routines for Object Tools and OBJ_GPBN is a
wrapper for Object get pointer(Object named).


When working with OB commands or OT commands, I use wrapper routines where
possible but, in this case, I'm using the 4D command because I want to use
a very, very nice feature that 4D included in OB Get - the Type parameter.
When creating a variable on a form, dynamic or otherwise, the Type is
important because it allows us to assign a filter/format. The Type
parameter of OB Get plays right into that.


While this isn't using Process tags, "it's the same (but different)" in
that it's a way to parse incoming JSON into variables.


After the first version of this code was released, we decided to add
another value coming back from SAP. All I had to do was create a dynamic
variable with a name that matched the name coming in from SAP XML payload,
select the variable and set the Type value in the property list, and assign
a format to the dynamic variable. Next time I got data back from SAP, the
tag in the JSON matched the name of the object on the form and the variable
was populated. No code change. No bugs. *Very* bueno.


BTW, we are using code from the 4D tech note component that converts XML to
JSON - many thanks to Timothy Tse for the tech note.




--
Douglas von Roeder
949-336-2902

On Sun, Oct 30, 2016 at 12:22 PM, Lee Hinde <[hidden email]> wrote:

> It feels like you'd have to use 4Deval.  But, I think I'd unpack a c_object
> with javascript once in the web page.
>
>
> On Sun, Oct 30, 2016 at 8:38 AM, Kirk Brooks <[hidden email]> wrote:
>
> > I haven't used Process Tabs very much but it is promising.
> >
> > I use javaScript and jQuery to turn JSON into web pages and web areas. I
> > thought I'd look at doing this on the 4D side with process tags but I
> can't
> > find a clean way to process data from a c-object. All my solutions are
> > overly involved which makes me think I'm missing something.
> >
> > Is anyone doing this also? Could you share a few tips on how you make it
> > work?
> >
> > Thanks
> >
> > --
> > Kirk Brooks
> > San Francisco, CA
> > =======================
> >
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************
>
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to use Process Tags with c-objects?

Keisuke Miyako
you just do something like:

<script>

var obj = $4DHTML(JSON Stringify(whatever));

or

var obj = <!--#4DHTML JSON Stringify(whatever)-->;

</script>



宮古 啓介
セールス・エンジニア

株式会社フォーディー・ジャパン
〒150-0043
東京都渋谷区道玄坂1-10-2 渋谷THビル6F
Tel: 03-6427-8441
Fax: 03-6427-8449

[hidden email]
www.4D.com/JP

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to use Process Tags with c-objects?

Lee Hinde
re: var obj = $4DHTML(JSON Stringify(whatever));


Say what? What's that $syntax?

2016-10-30 15:53 GMT-07:00 Keisuke Miyako <[hidden email]>:

> <script>
>
> var obj = $4DHTML(JSON Stringify(whatever));
>
> or
>
> var obj = <!--#4DHTML JSON Stringify(whatever)-->;
>
> </script>
>
>
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to use Process Tags with c-objects?

Keisuke Miyako
"Alternative syntax for 4DTEXT, 4DHTML, 4DEVAL"

http://doc.4d.com/4Dv15R5/4D/15-R5/4D-Transformation-Tags.300-2936578.en.html

since 15R4

> 2016/10/31 9:19、Lee Hinde <[hidden email]> のメール:
> re: var obj = $4DHTML(JSON Stringify(whatever));
> Say what? What's that $syntax?


宮古 啓介
セールス・エンジニア

株式会社フォーディー・ジャパン
〒150-0043
東京都渋谷区道玄坂1-10-2 渋谷THビル6F
Tel: 03-6427-8441
Fax: 03-6427-8449

[hidden email]
www.4D.com/JP

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to use Process Tags with c-objects?

Lee Hinde
Ah, R release. Thanks!

> On Oct 30, 2016, at 7:15 PM, Keisuke Miyako <[hidden email]> wrote:
>
> "Alternative syntax for 4DTEXT, 4DHTML, 4DEVAL"
>
> http://doc.4d.com/4Dv15R5/4D/15-R5/4D-Transformation-Tags.300-2936578.en.html
>
> since 15R4
>
>> 2016/10/31 9:19、Lee Hinde <[hidden email]> のメール:
>> re: var obj = $4DHTML(JSON Stringify(whatever));
>> Say what? What's that $syntax?
>
>
> 宮古 啓介
> セールス・エンジニア
>
> 株式会社フォーディー・ジャパン
> 〒150-0043
> 東京都渋谷区道玄坂1-10-2 渋谷THビル6F
> Tel: 03-6427-8441
> Fax: 03-6427-8449
>
> [hidden email]
> www.4D.com/JP
>

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to use Process Tags with c-objects?

KirkBrooks
In reply to this post by Keisuke Miyako
Hi Miyako,
Yes, that's what I do now to initiate a page and then parse with js.

After a little more playing around I find this works:

<!--#4DEVAL OB GET(jsonObj;"key";Is longint)-->


We don't currently have any way to iterate over elements of an array within
the object but this is something to work with.


2016-10-30 15:53 GMT-07:00 Keisuke Miyako <[hidden email]>:

> you just do something like:
>
> <script>
>
> var obj = $4DHTML(JSON Stringify(whatever));
>
> or
>
> var obj = <!--#4DHTML JSON Stringify(whatever)-->;
>
> </script>
>
>
>
> 宮古 啓介
> セールス・エンジニア
>
> 株式会社フォーディー・ジャパン
> 〒150-0043
> 東京都渋谷区道玄坂1-10-2 渋谷THビル6F
> Tel: 03-6427-8441
> Fax: 03-6427-8449
>
> [hidden email]
> www.4D.com/JP
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************
>



--
Kirk Brooks
San Francisco, CA
=======================
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to use Process Tags with c-objects?

Tom DeMeo
In reply to this post by KirkBrooks
Hi Kirk,


You really have 4 modes you can always work with.

1. You can process data in 4D code and call a method from process tag code.
2. You can process data using embedded process tag code itself
3. You can inject the data as json into the page using tags, and process it using javascript client side
4. You can request the data from the server separately using an ajax call, and process it using javascript client side


You appear to be investigating how to work best with scheme #2, but that is by far the least appealing of the 4 choices.

While we now have ways to work with objects in 4D, I would argue that it is always far easier to use object data with javascript, as long as you are comfortable enough working with it.

When you are building a page, you have the initial load, and then you have any interactivity you may need afterward, which requires ajax. Tags only apply to the initial load of the page, so any work done that way can’t be reused for anything. That’s why tags are most useful for quick and dirty static pages. If you have a choice and you might have interactive pages, it’s always best to stick with scheme #4, because the initial load and the subsequent actions all can be done in one consistent way


Tom D

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to use Process Tags with c-objects?

KirkBrooks
Hi Tom,
Yeah, nice summary of working with tags. And yeah I am playing with doing
some processing in the tags after reading Charlie Voss' tech note from last
year or so. In general I build my 4D side methods to generate c-obj/JSON as
output. I was playing with the idea of being able to produce 'html tag
pages' (for a made-up expression) that would do the same work as the
javascript. It's not looking too good for that. I think Process Tags is a
cool feature but not really the solution I'm looking for in this case.

On Mon, Oct 31, 2016 at 9:36 AM, Tom DeMeo <[hidden email]>
wrote:

> Hi Kirk,
> You really have 4 modes you can always work with.
>


--
Kirk Brooks
San Francisco, CA
=======================
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to use Process Tags with c-objects?

Keisuke Miyako
In reply to this post by KirkBrooks
4DEVAL is designed for expressions that may or may not return a value.

OB Get always returns a value,
so it more natural to use 4DTEXT or 4DHTML.

but I guess you meant something like

        <!--#4DEVAL $key:=OB Get(jsonObj;"key";Is longint)-->

*

as for iterating over elements of an array,
you can obtain the array with 4DEVAL+OB GET ARRAY,
and pass that local array to 4DLOOP.

you can also embed many lines of 4D code with 4DCODE (15r4).

having said that, I agree with Tom D,
it's better to decouple the data from the page and use AJAX instead.

> 2016/10/31 11:36、Kirk Brooks <[hidden email]> のメール:
> <!--#4DEVAL OB GET(jsonObj;"key";Is longint)-->
> We don't currently have any way to iterate over elements of an array within
> the object but this is something to work with.



宮古 啓介
セールス・エンジニア

株式会社フォーディー・ジャパン
〒150-0043
東京都渋谷区道玄坂1-10-2 渋谷THビル6F
Tel: 03-6427-8441
Fax: 03-6427-8449

[hidden email]
www.4D.com/JP

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************