Topic
  • 4 replies
  • Latest Post - ‏2014-08-06T05:04:24Z by HaydenMc
HaydenMc
HaydenMc
9 Posts

Pinned topic Updating a Global Variable in a macro

‏2014-07-09T22:42:16Z |

Hi All

We've got a restful service calling a macro which returns a couple of global variables.  Both global variables are set/updated in a macro but one is only set once, whilst the other we are attempting to set twice (or multiple times).

The GV that is updated only once is returned fine.  The other one doesn't have a value returned.  A couple of questions come from this.

1.  How do we reference a GV from inside a macro?  Can we use the updatevar feature?

2. What does the overwrite/append options do to a GV when setting from an extract?

3. Is there a better way?  Should we be using macro variables and somehow returning those to the REST service?

Thanks

 - Hayden

  • tmparker
    tmparker
    534 Posts
    ACCEPTED ANSWER

    Re: Updating a Global Variable in a macro

    ‏2014-07-11T16:53:41Z  
    • HaydenMc
    • ‏2014-07-10T22:01:42Z

    Thanks Tim.

    Unfortunately I'm still learning the lingo, and trying to understand what an "integration object" is in the HATS context.  We are also trying to use HATS to record macros called thru RESTful services, but not do the full web integration thing, so we're staying away from normal web stuff.  I guess I'm thinking a GV is like any other variable in any language, in that it can be updated.  Even the macro variables can be updated.  But the GV in a macro only seem to be updatable through the extract action - is that correct?  And only once?  And when declaring the GV in that extract action, there are 4 options - Overwrite, Overwrite starting at index, Append, and Insert at index.  Do these do anything?  I can't find anything in the help about that popup box.

    And I see the "shared" option, but I thought I read that it shared the variable across sessions, and we don't want that for returning an error message to the user through the web service.

    I've attached a pic of my extract action for the error message and my current settings.

    Also, I see that in the <extracts> section of the hma, the line:

    <extract handler="default.jsp" index="0" indexed="false" name="errMessage" overwrite="true" planetype="TEXT_PLANE" save="true" separator="" showHandler="true" updateVariableImmediately="false" variableName="errMessage"/>
    

    How does updateVariableImmediately change things?  Again, I can't find this documented anywhere.

    Thanks for your link to the other reply you gave.  I'll hand that over to the guys looking after the restful service, and see if they can do anything with it.  Looks like we'll have to get a Java programmer more involved than they were.

    One thing I was hoping for was to just keep on appending to that errMessage GV, as we get a number of messages appear through the macro, and it would be good to return all of them thru the service to the user.  But if it's referenced more than once, we seem to get nothing.

    I can attach the macro if you want.

    Thanks for your help

     - Hayden

     

    Hi Hayden,

    Everything you referenced above is correct when you are creating macros that run in the normal web context.  You can extract GV multiple times, append to them, etc...  However, when you create web services out of the macros GV are no longer the same thing.  When the project is running web services we don't actually create all the HATS objects under the covers, and this includes the Business Logic objects which are needed to handle the GV.  Extracts are used to return data and, as the documentation states, we don't directly extract data to GV and instead the extracts are fulfilled after the web service is run.  Just to be clear, an Integration Object is a Java bean that can be called directly or be used as the building block for creating web services.  To do customizations for IOs or web services, you really need to work with the IO template.  You can add custom code in there that can allow you to do much more.  If you look at the other thread I added a link to above, you will see what I am referring to with modifying the template.  If you modify the template itself then it will be applied to the IO every time you need to generate it so your changes won't be lost.

    Hopefully this helps explain it a little.  Let me know how your development work goes and if we can be of any other assistance.

    Thanks
    Tim

  • tmparker
    tmparker
    534 Posts

    Re: Updating a Global Variable in a macro

    ‏2014-07-10T17:34:12Z  

    Hi Hayden,

    I'm not sure how your macro is setup exactly so it's hard for me to say if there is a better way to do it.  However, if you look in the InfoCenter here, http://pic.dhe.ibm.com/infocenter/hatshelp/v90/topic/com.ibm.hats.doc/doc/mac_vme.htm, you will find the following statement, "Integration Objects do not directly extract to global variables. Instead, the output page for the Integration Object retrieves the data from the Integration Object after it has run, and then sets the global variables. Remember only shared global variables can be accessed by Integration Objects."

    With that said, doing updates during the macro won't be seen at the end.  Global variables are not the same as they are in normal web projects.  Each extract will return a single value.

    Take a look at this other thread I responded to and see if this helps explain it any better.
    https://www.ibm.com/developerworks/community/forums/html/topic?id=33858827-1f28-4386-9707-b9a9bab1425e&ps=25

    Let me know if you have other questions and I can see what we can come up with to find a solution for you.

    Thanks
    Tim

  • HaydenMc
    HaydenMc
    9 Posts

    Re: Updating a Global Variable in a macro

    ‏2014-07-10T22:01:42Z  

    Thanks Tim.

    Unfortunately I'm still learning the lingo, and trying to understand what an "integration object" is in the HATS context.  We are also trying to use HATS to record macros called thru RESTful services, but not do the full web integration thing, so we're staying away from normal web stuff.  I guess I'm thinking a GV is like any other variable in any language, in that it can be updated.  Even the macro variables can be updated.  But the GV in a macro only seem to be updatable through the extract action - is that correct?  And only once?  And when declaring the GV in that extract action, there are 4 options - Overwrite, Overwrite starting at index, Append, and Insert at index.  Do these do anything?  I can't find anything in the help about that popup box.

    And I see the "shared" option, but I thought I read that it shared the variable across sessions, and we don't want that for returning an error message to the user through the web service.

    I've attached a pic of my extract action for the error message and my current settings.

    Also, I see that in the <extracts> section of the hma, the line:

    <extract handler="default.jsp" index="0" indexed="false" name="errMessage" overwrite="true" planetype="TEXT_PLANE" save="true" separator="" showHandler="true" updateVariableImmediately="false" variableName="errMessage"/>

    How does updateVariableImmediately change things?  Again, I can't find this documented anywhere.

    Thanks for your link to the other reply you gave.  I'll hand that over to the guys looking after the restful service, and see if they can do anything with it.  Looks like we'll have to get a Java programmer more involved than they were.

    One thing I was hoping for was to just keep on appending to that errMessage GV, as we get a number of messages appear through the macro, and it would be good to return all of them thru the service to the user.  But if it's referenced more than once, we seem to get nothing.

    I can attach the macro if you want.

    Thanks for your help

     - Hayden

     

    Attachments

  • tmparker
    tmparker
    534 Posts

    Re: Updating a Global Variable in a macro

    ‏2014-07-11T16:53:41Z  
    • HaydenMc
    • ‏2014-07-10T22:01:42Z

    Thanks Tim.

    Unfortunately I'm still learning the lingo, and trying to understand what an "integration object" is in the HATS context.  We are also trying to use HATS to record macros called thru RESTful services, but not do the full web integration thing, so we're staying away from normal web stuff.  I guess I'm thinking a GV is like any other variable in any language, in that it can be updated.  Even the macro variables can be updated.  But the GV in a macro only seem to be updatable through the extract action - is that correct?  And only once?  And when declaring the GV in that extract action, there are 4 options - Overwrite, Overwrite starting at index, Append, and Insert at index.  Do these do anything?  I can't find anything in the help about that popup box.

    And I see the "shared" option, but I thought I read that it shared the variable across sessions, and we don't want that for returning an error message to the user through the web service.

    I've attached a pic of my extract action for the error message and my current settings.

    Also, I see that in the <extracts> section of the hma, the line:

    <pre class="html dw" data-editor-lang="js" data-pbcklang="html" dir="ltr"><extract handler="default.jsp" index="0" indexed="false" name="errMessage" overwrite="true" planetype="TEXT_PLANE" save="true" separator="" showHandler="true" updateVariableImmediately="false" variableName="errMessage"/></pre>

    How does updateVariableImmediately change things?  Again, I can't find this documented anywhere.

    Thanks for your link to the other reply you gave.  I'll hand that over to the guys looking after the restful service, and see if they can do anything with it.  Looks like we'll have to get a Java programmer more involved than they were.

    One thing I was hoping for was to just keep on appending to that errMessage GV, as we get a number of messages appear through the macro, and it would be good to return all of them thru the service to the user.  But if it's referenced more than once, we seem to get nothing.

    I can attach the macro if you want.

    Thanks for your help

     - Hayden

     

    Hi Hayden,

    Everything you referenced above is correct when you are creating macros that run in the normal web context.  You can extract GV multiple times, append to them, etc...  However, when you create web services out of the macros GV are no longer the same thing.  When the project is running web services we don't actually create all the HATS objects under the covers, and this includes the Business Logic objects which are needed to handle the GV.  Extracts are used to return data and, as the documentation states, we don't directly extract data to GV and instead the extracts are fulfilled after the web service is run.  Just to be clear, an Integration Object is a Java bean that can be called directly or be used as the building block for creating web services.  To do customizations for IOs or web services, you really need to work with the IO template.  You can add custom code in there that can allow you to do much more.  If you look at the other thread I added a link to above, you will see what I am referring to with modifying the template.  If you modify the template itself then it will be applied to the IO every time you need to generate it so your changes won't be lost.

    Hopefully this helps explain it a little.  Let me know how your development work goes and if we can be of any other assistance.

    Thanks
    Tim

  • HaydenMc
    HaydenMc
    9 Posts

    Re: Updating a Global Variable in a macro

    ‏2014-08-06T05:04:24Z  
    • tmparker
    • ‏2014-07-10T17:34:12Z

    Hi Hayden,

    I'm not sure how your macro is setup exactly so it's hard for me to say if there is a better way to do it.  However, if you look in the InfoCenter here, http://pic.dhe.ibm.com/infocenter/hatshelp/v90/topic/com.ibm.hats.doc/doc/mac_vme.htm, you will find the following statement, "Integration Objects do not directly extract to global variables. Instead, the output page for the Integration Object retrieves the data from the Integration Object after it has run, and then sets the global variables. Remember only shared global variables can be accessed by Integration Objects."

    With that said, doing updates during the macro won't be seen at the end.  Global variables are not the same as they are in normal web projects.  Each extract will return a single value.

    Take a look at this other thread I responded to and see if this helps explain it any better.
    https://www.ibm.com/developerworks/community/forums/html/topic?id=33858827-1f28-4386-9707-b9a9bab1425e&ps=25

    Let me know if you have other questions and I can see what we can come up with to find a solution for you.

    Thanks
    Tim

    Thanks Tim.  A month or so later, and looking at more detail into these Integration Objects, and I'm starting to understand what is going on (well, a little bit anyway), and the examples in that other thread make some sense.

    So only 'extract' values from a macro are available to the Integration Object, but you added in a method & variable - internalMV - that provides another way...  That might help a bit.  Right now I'm more keen to get a better handle on timeouts (refer my other post in the forum), but I can see this method getting some use.

    Cheers