Calling URL from a NiceLabel application?

Label printing integration (NiceWatch middleware and ActiveX programming interface)

Moderators: Georges, milos, NiceLabel Support Team

robdavis
Enthusiast
Posts: 16
Joined: Fri Jun 11, 2010 2:54 pm

Calling URL from a NiceLabel application?

Post by robdavis » Fri Jun 11, 2010 3:09 pm

Can I call a HTTP URL GET request from a NiceLabel application? I don't think this is possible in NiceForm but is it possible in NiceWatch?

I see that there are triggers in NiceWatch - and there is one for TCP/IP but the set up form for this doesn't appear to be meant for URL calls.

Any other applications in the NiceLabel suite that support URL calls directly to get information for use on labels?

User avatar
dado
NiceLabel Development
NiceLabel Development
Posts: 691
Joined: Tue Sep 12, 2006 12:50 pm
Location: Kranj, Slovenia
Contact:

Re: Calling URL from a NiceLabel application?

Post by dado » Sat Jun 12, 2010 11:15 am

You can use Visual Basic Script. This example will read something from the yahoo page.

Code: Select all

With CreateObject("MSXML2.XMLHTTP")
  .open "GET", "http://news.yahoo.com/news?tmpl=index&cid=586&/", False
  .send
  t =.responseText
End With
MsgBox(t)
Regards

Damjan

robdavis
Enthusiast
Posts: 16
Joined: Fri Jun 11, 2010 2:54 pm

Re: Calling URL from a NiceLabel application?

Post by robdavis » Mon Jun 14, 2010 11:04 am

dado wrote:You can use Visual Basic Script. This example will read something from the yahoo page.

Code: Select all

With CreateObject("MSXML2.XMLHTTP")
  .open "GET", "http://news.yahoo.com/news?tmpl=index&cid=586&/", False
  .send
  t =.responseText
End With
MsgBox(t)
Regards

Damjan
Thank you very much Damjan, this should work for me! :D

robdavis
Enthusiast
Posts: 16
Joined: Fri Jun 11, 2010 2:54 pm

Re: Calling URL from a NiceLabel application?

Post by robdavis » Mon Jun 14, 2010 12:25 pm

dado wrote:You can use Visual Basic Script. This example will read something from the yahoo page.

Code: Select all

With CreateObject("MSXML2.XMLHTTP")
  .open "GET", "http://news.yahoo.com/news?tmpl=index&cid=586&/", False
  .send
  t =.responseText
End With
MsgBox(t)
Regards

Damjan
I need advice on how to get this returned data into the label before it is printed. Can you set the NiceLabel label variables directly from this VBScript? E.g. if I have a variable 'sn', can I do: sn =.responseText so that the label variable sn contains the data returned from our server?

Or does the VBScript have to write the returned data to a file which is then obtained for the label using a 'Load variable data' action?

User avatar
dado
NiceLabel Development
NiceLabel Development
Posts: 691
Joined: Tue Sep 12, 2006 12:50 pm
Location: Kranj, Slovenia
Contact:

Re: Calling URL from a NiceLabel application?

Post by dado » Mon Jun 14, 2010 1:04 pm

To get the data to the label you need to set the variable in VBS:

Code: Select all

Result = "Some text here"
Then you can place the function that you created on your label as text.

I've created a quick sample for you.

It goes to a web page where it recieves the data from that page. Then it goes through the data and removes everything except the IP that is then showed on the label.
GetUrlLabel.lbl
(144 KiB) Downloaded 265 times
Regards

Damjan

robdavis
Enthusiast
Posts: 16
Joined: Fri Jun 11, 2010 2:54 pm

Re: Calling URL from a NiceLabel application?

Post by robdavis » Mon Jun 14, 2010 3:20 pm

Thanks Damjam I will check it out.

robdavis
Enthusiast
Posts: 16
Joined: Fri Jun 11, 2010 2:54 pm

Re: Calling URL from a NiceLabel application?

Post by robdavis » Mon Jun 14, 2010 3:28 pm

dado wrote:GetUrlLabel.lbl
This is done within NiceLabelPro within the label, not within NiceForm. That's fine, but I was trying to do it in NiceForm. Is it possible to run the script in NiceForm and pass the variable back to the .lbl ?

Or perhaps, myself, I should re-think where I am calling our server. Perhaps it is only necessary to call it from within the label .lbl instead of NiceForm. Perhaps I don't need to call it from NiceForm at all.

That re-thinking is a decision our company/team has to make, whether we need to do it in NiceForm. I think that we might not have to do it from NiceForm and therefore I could use your example as a basis.

robdavis
Enthusiast
Posts: 16
Joined: Fri Jun 11, 2010 2:54 pm

Re: Calling URL from a NiceLabel application?

Post by robdavis » Mon Jun 14, 2010 3:37 pm

Had a quick chat with one of my colleagues and the data we need from our server depends on the kind of label we want to print, so your example, Damjam, makes perfect sense to us.

We plan to use one NiceForm form as a 'launchpad' for printing different kinds of labels. We don't really want to try to call our server for label data from NiceForm as we might be calling it for data that we don't need for a specific label that we print via the form.

So, having the .lbl file contain parameter request data, specific to that label, in the HTTP GET URL call to our server makes perfect sense. We vary the URL string per label to reflect what we want.

Thanks Damjam.

robdavis
Enthusiast
Posts: 16
Joined: Fri Jun 11, 2010 2:54 pm

Re: Calling URL from a NiceLabel application?

Post by robdavis » Mon Jun 14, 2010 4:31 pm

Damjam, One other very important thing:

Can we confirm that NiceLabel does NOT cache the result message received from the server?

We need to make sure that it does not, so that each label printed has fresh data from the server.

In other words, each time NiceLabel attempts to populate the label with the variable data for printing, the VBScript is run and the server call is made and no cached earlier data from a previous server call is used.

User avatar
Saso
NiceLabel
NiceLabel
Posts: 2968
Joined: Mon Sep 04, 2006 8:09 am
Contact:

Re: Calling URL from a NiceLabel application?

Post by Saso » Mon Jun 14, 2010 5:49 pm

NiceLabel does not cache this information.
Each call to the Web application will be unique.

If you will use the VB script function within the label (not in NiceForm), be aware that function will not only execute at printing, but also when:
  • Previewing the label.
  • Opening the label when you have Data view enabled (View menu -> Data).
You can put a check in your VB script and execute it only when the user is really printing the label. NiceLabel can determine the label state (design, preview, print)...

Like this:

Code: Select all

CurrentState = Label.GetCurrentState
select case CurrentState
  case 0 Result = "Label design"
  case 1 Result = "Print"
  case 2 Result = "Print preview"
end select
Saso Fleiser
Senior Technical Product Specialist

robdavis
Enthusiast
Posts: 16
Joined: Fri Jun 11, 2010 2:54 pm

Re: Calling URL from a NiceLabel application?

Post by robdavis » Mon Jun 14, 2010 5:56 pm

Thanks Saso. That is the answer that I expected - and wanted. That is re-assuring!

The script you provide is also useful - thank you.

User avatar
Saso
NiceLabel
NiceLabel
Posts: 2968
Joined: Mon Sep 04, 2006 8:09 am
Contact:

Re: Calling URL from a NiceLabel application?

Post by Saso » Tue Jun 15, 2010 9:47 pm

More detailed information for the XMLHttpRequest object and some usage hints are available in MSDN Library.
Saso Fleiser
Senior Technical Product Specialist

robdavis
Enthusiast
Posts: 16
Joined: Fri Jun 11, 2010 2:54 pm

Re: Calling URL from a NiceLabel application?

Post by robdavis » Wed Jun 16, 2010 5:04 pm

Dado,
can you advise me on how to turn off the cache in VBScript - I believe the Windows component (outside of NiceLabel/NiceForm) is cacheing the data from our server.

Thanks,
Rob.

robdavis
Enthusiast
Posts: 16
Joined: Fri Jun 11, 2010 2:54 pm

Re: Calling URL from a NiceLabel application?

Post by robdavis » Wed Jun 16, 2010 6:58 pm

Also posted the issue with VBScript caching (generally) here:

http://stackoverflow.com/questions/3055 ... rl-request

User avatar
dado
NiceLabel Development
NiceLabel Development
Posts: 691
Joined: Tue Sep 12, 2006 12:50 pm
Location: Kranj, Slovenia
Contact:

Re: Calling URL from a NiceLabel application?

Post by dado » Wed Jun 16, 2010 7:28 pm

Unfortunatelly I don't have an answer to this question :( I hope you'll find someone that'll be able to help you in the forum above.

Regards

Damjan

Post Reply