cancel
Showing results for 
Search instead for 
Did you mean: 

Agentry: Example of iOS Attachment download/display

MattHarding
Active Contributor
0 Kudos

Hi There,

Just trying to help someone out here and I've looked through all the logical resources including the SCN wiki, resource.syclo.com, sybase.com (SMP 2.3 SP3 and 3.0) and can't find an example or instructions on how this really works for iOS (all examples show the External Data Property window for Windows only).

So some points about what I suspect you need to do (forgive my ignorance) -

You need an object for your attachments as a best practice with an external data property.

Key question at this point are:

  • It seems you are forced to use the file system as an interim step.
  • If using a BAPI from SAP, exporting RFC parameters of xstring or string are not supported hence you need to rely on tables which don't support variable length fields, hence you need to first convert files to this table of fixed length raw data with a length property to represent the file(s); which within your JAVA classes you need to disect and convert back to put them on the Agentry file system.
  • The external data properties for iOS include Application Support, Documents and iOS Photo Library (guessing the last one is read-only and no idea the difference between the next two).
  • Relative Path is a bit cryptic as there is no help about what this looks like on iOS for any of the above
  • I can't see the link between Client File and the file object created above, but one guide refered to an SDML script to link the two but was very cryptic in terms of how it was linked.
  • Every user will download the same files to different directory/filename locations in order to synchronise since typically you should archive the file from SMP after synchronisation.

In short, anyone have an updated blog/guide around this or willing to write one? I'd also be happy with some short answers to my questions/thoughts above.

Thanks for reading,

Matt

ps. Here's some of the sybase.com older doco all Windows focused: http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.pubs.docset-SMP-SDK-3.0.0/d...


Accepted Solutions (1)

Accepted Solutions (1)

MattHarding
Active Contributor
0 Kudos

BTW - This was the best resource I found (which doesn't appear to have been copied across to SCN):

https://sycloresourcecenter.sap.com/development/kb/example-attachment-functionality-smart-service-ma...

0 Kudos

Hi Matt

For Downloading to a IOS device its been simplified a lot you no longer need to do any file connections or transfers. You can pass a Xstring to a External File as a base64 encoded string. The client will write your file for you automaticly.

Example of code

* Get my xstring data from my Bapi and convert to Base64

String s = encodeBase64(filedatatbl.getByteArray("XSDATA");

* Set FileData this is a String in your Object class NOT BYTES[]

DocLink.setFileData(s);

FileData is mapped to a  External Data Field. You still have to map a File Name + Extension and set the Download Path in the External Data Object.

All you have to then is map the External Data Field to a Html Control.

Use the latest version of the client newer like 6.0.36

MattHarding
Active Contributor
0 Kudos

Thanks Rikardt. That sounds very promising (unless Mark comes back with - "sorry that's SAP Work Manager 6.0 functionality on a ramp-up version of agentry only") - Will tell the guys and see if we can get this working.  From the looks of it, setFileData is the key to this...

Just for my understanding, is your getByteArray a custom method to translate the raw data table into a file and are you just handling single files from the BAPI request at the moment? - I'm reading a lot into that one line you have written...

0 Kudos

Its actually a lot simpler than that. getByteArray is a standard method it just converts a xstring to a Byte Array the below code is something I have been playing around in Work Manager . It adds documents underneath a Order Object. Its pretty rough was doing it as a proof of concept. SAP does their attachements in a similar  way.

All I have is a ExternalData field called FileData in a Object (Doclink) added as a collection underneath a Work Order object.  FileData in the Doclink class(JAVA)  is a String it maps to the FileData field.The mapping is the same as any field.

Example of the filling code


    Table filedatatbl = _imports.getTable("ET_FILEDATA");
  
      int numRows = filedatatbl.getNumRows();
     
         for (int x = 0; x < numRows; x++)
         {    
         
         
          filedatatbl.setRow(x);
         
      
         if ( filedatatbl.getString("ZFILENAME") ==  tbl.getString("AUFNR"))
         {

              
         String s = encodeBase64(filedatatbl.getByteArray("ZFILEDATA"));

     

       DocLink.setID(tbl.getString("AUFNR") ); 
       DocLink.setFileType("pdf");

       DocLink.setFileName(tbl.getString("AUFNR") + ".pdf");

       DocLink.setFileData(s);

       docObjects.add(DocLink);
      
         }

}

Encoding - Sap uses a different one but I prefer this library

   

public String encodeBase64(byte abyte0[])

{
return org.apache.commons.codec.binary.Base64.encodeBase64String(abyte0);

}

O yes use Itunes to check if the files have downloaded. You can see it under Apps scroll to the bottom and select Agentry you should be able to see the files. Sync Itunes to refesh after download.

You will also have to deploy Work Manager to the newest Agentry server version available. It does not work on older versions before 6.032.0 I believe. 

MattHarding
Active Contributor
0 Kudos

That's awesome Rikardt. I think we should be right with all that information from you and Mark, and will post back our full design/code (from our perspective) when we get it all working (I'm just the middleman unfortunately but these replies should hopefully encourage more interaction with SCN since it's been so beneficial posting here. If you'd like to post a full end to end blog on the above, I will definitely like and bookmark that one 😉

Cheers,

Matt

agentry_src
Active Contributor
0 Kudos

Hi Matt,

Just an aside, but also for others out there, the SRC documents are coming over, but it is a somewhat manual process to get them each formatted for the SCN document submission process and reviewed for updated features and functions.  Please continue to use the SRC, but also go to the Agentry Landing page where we are linking the docs, blogs, etc. as they are released.

Regards, Mike

SAP Rapid Innovation Group - RIG

MattHarding
Active Contributor
0 Kudos

Thanks Michael. Plenty of work to do I'm sure and appreciate transitioning fully to SAP will take a while - but hopefully the community side of Agentry grows rapidly now that it is a core part of SMP.

agentry_src
Active Contributor
0 Kudos

I think it is going pretty well.  Here is an example of how well people are working in this community.  http://scn.sap.com/thread/3449087

MattHarding
Active Contributor
0 Kudos

Hi Rickard,

I decided today to just go ahead and do this myself (creating a new Agentry app to do it), but one question: How have you defined ZFILEDATA within ABAP? e.g. I've ended up defining two exporting tables. One for filename/filetype/length, and the other for a table of raw data 1024 bytes long. 

Your example seems to contain one table (that supports multiple files), with a field that holds the document (ZFILEDATA) but I can't understand how this can hold a large file without defining it as a very large RAW field (due to RFC table limitations)!

e.g. I'd love to pass an xstring or even a string from ABAP to Agentry!

Hopefully that question makes sense.

Cheers,

Matt

0 Kudos

Hi Matt

You define the element as as a RawString.

Below is screenshots of the structure , Table type and where I placed it in the RFC Function. I also added some abap code at the end that shows how you pass a xstring. Its a straight mapping.

Structure

Table Type

RFC

Example Abap:

Data: lv_xs type xstring.

* Get your xstring here and place in lv_xs


LS_FILEDATA-ZFILEDATA = lv_xs.


if lv_xs is not initial.
APPEND LS_FILEDATA  TO  ET_FILEDATA.
endif.

Regards

Rikardt

MattHarding
Active Contributor
0 Kudos

Oh wow - You just added a huge capability to my Agentry development skills as I was not aware that Agentry could handle exporting tables the same way it handles table "tables". All the BAPI examples I came across seemed to be limited to using the Tables area (not exporting area) which obviously don't support rawstring types for RFC.

FYI - I actually asked this question about using exporting parameters at TechEd but obviously didn't ask the right person.

Thanks yet again!

Cheers,

Matt

MattHarding
Active Contributor
0 Kudos

FYI (Rickardt) - In your example, I needed to change your example to obviously use _exports instead of _imports, but looks like that did the trick (didn't realise I could access exports/imports before so pretty straightforward - except for the mysterious file transfer).

  Table filedatatbl = _imports.getTable("ET_FILEDATA"); should be

  Table filedatatbl = _exports.getTable("ET_FILEDATA");

Blog coming soon to summarise this (hopefully)...

0 Kudos

Hi Matt

Glad it worked. You are correct about the _exports . It was a proof of concept so I  never changed the parameter in my method .

Just for intrest sake it seems you can upload a file to the server as well using this technique by just passing the binary back.


String prefix =

"transaction.workorder.documentlink";


JCO.Table tbl =

_imports.getTable("IT_FILEDATA");


// add Answers


int sz = Integer.parseInt(_user.eval("<<size " + prefix + ">>"));


if (sz > 0) {



for (int i = 0; i < sz; i++) {



tbl.appendRow();


try {


tbl.setValue(

_user.getSessionData().getBytes(prefix + "." + i + ".FileData.Data"),"ZFILEDATA" );


}

catch (AgentryException e) {


// TODO Auto-generated catch block


e.printStackTrace();


}



}



}


}

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi there,

We are using Agentry plug-in 6.1.3.10212 which is aligned with the SAP Mobile Platform 2.3 Service Pack 03 Patch Level 01:

Regards,

Roman

Former Member
0 Kudos

Thanks Roman for the quick response.

I downloaded SMP2.3 from SSMP but couldn't find the Agentry Plug-in.

Any change you have a link where to download the Plug-in? Also, any idea if this version of the Plug-in will work on a stand-alone SAP Work Manager Server v5.3.0.0?

Regards,

Parker

Former Member
0 Kudos

Hi Parker,

As far as I recall, the Agentry Plug-in sits under "SAP Mobile SDK 2.3".

Inside that download ZIP there should be a file called Agentry-Dev-Tools-2.3.zip
That's where you will find the Agentry Eclipse plug-in (for 32 and 64-bit environments) as well as Agentry Test Environment utility and the Agentry standalone Dev server.

The plug-in should work on both SMP and standalone Dev Agentry server, however there is an issue when running the standalone Dev Agentry server as a "Windows service" (refer to earlier reply from Bill Froelich)

Also, from what I understand, SAP are now advising customers to move from standalone Agentry to SMP.  Standalone Agentry for development purposes is OK.  But for proper deployment, hosting and monitoring of production Agentry apps, the recommendation going forward is to use SMP.

Hope this helps.

Regards,

Roman.

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Parker,

The version of the Agentry Editor plug in you are using should match the version of the Agentry/SMP server you are deploying to.

SAP Work Manager 5.3 was released using Agentry 6.0.x as the platform.  I know there are folks who have upgraded the platform to SMP 2.3 (and possibly SMP 3) to run it.  In these cases they would have also upgraded their Agentry Editor and imported the definitions into the new editor as well as published out from the new Editor to the server.

The standalone Agentry server still exists in SMP 2.3 for development purposes but for production you should deploy to the SMP 2.3 server.   With SMP 3.0, there is no more standalone Agentry server as it is integrated into the SMP 3.0 sever and used for both development and production.

--Bill

Former Member
0 Kudos

Thanks Bill/Roman for the information, they're very helpful.

So far I have no luck on my tests on using Editor Plug-in of SMP 2.3 for Agentry 6.0.x platform to display uploaded attachment to iPad using HTML.

I will check the implication on the licenses if we upgrade to SMP 2.3 now since we are still in development stage.

Regards,

Parker

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

If youa re using Agentry 6.0.x for the server you should get corresponding Agentry Editor PlugIn to match.  We do not recommend using teh SMP 2.3 Editor with an Agentry 6.0.x server.

--Bill

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Just to clarify on the following a bit further:

  • The external data properties for iOS include Application Support, Documents and iOS Photo Library (guessing the last one is read-only and no idea the difference between the next two).
  • Relative Path is a bit cryptic as there is no help about what this looks like on iOS

For the External Data choices

  • Application Support - Will create a folder using the relative path value underneath the application container on iOS.  This directory is not exposed through iTunes but can be viewed using other tools (like iExplorer or iFunBox).
  • Documents - Will create a folder using the relative path value underneath the Documents portion of the application container.  This directory is exposed through iTunes and you can use iTunes to upload / download documents from this location.

You also want to make sure you are using the Agentry client 6.0.36 or above or 6.1.3 PL01 on the SMP2.3 side.  There was a bug that was fixed related to the attached documents being cleared unexpectedly fixed in these versions.

--Bill

Former Member
0 Kudos

Gentlemen,

Apologies for joining the conversation somewhat late. Matt has kindly been forwarding the SCN thread posts on to me and I've been doing most of the actual implementation work for our Work Manager solution here at Hydro Tasmania.  Thank you all very much for your guidance and feedback.

I do have a quick technical follow-up question which you might be able to help me with:

We've now got the mechanism working flawlessly except for the last part where a PDF file is meant to be displayed via the HTML control. The Agentry object is successfully populated and its External Data property successfully contains the actual file itself (which I can see in iTunes!!) So the RAWSTRING data with Base64 decoding on the Java side made the trick!  But displaying the file in HTML control seems a bit of a challenge.

My settings for the "DocumentFileContents" External Data property of the object are as follows:

File Name: "DocumenFileName" property of the object
Extension: Hard-coded to "PDF" for now
iOS File Location:
- Base Path: "Documents"
- Relative Path: <blank>

On the actual HTML control field, there's not much to configure. I bind the control to the "DocumentFileContents" External Data property, skip the Domains settings and make sure to switch to "Prohibited Domains".

We are on the latest patch levels of everything (i.e. iOS 7.0.4, Agentry client 6.1.3.10212, SMP 2.3 Support Pack 03 Patch Level 01)

Any ideas on what I might be missing??

Thanks in advance,
Roman.

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Are you getting any errors on the HTML control when trying to view the attachment?

The only two differences I can tell from what you mention and my setup is I do not have anything set for the File Extension on the External Data object property (Mine is blank) and for my file location I have a relative path specified so the attachments all go into a folder underneath the locaiton.

--Bill

Former Member
0 Kudos

Thank you for getting back to me, Bill.  I got it working!

I tried to remove the hardcoded File Extension on the object's External Data property and to use subdirectories for relative file locations. Got the same outcome as before.

But then I decided to double-check all the object target references on the actual Agentry screen definition itself - and therein lied the problem! My "Object Property" on the HTML control had a broken target reference. Once I pointed it to the correct object's External Data property everything worked perfectly. See the screenshots below:

Thanks again,

Roman.

Former Member
0 Kudos

Hi Bill,

An interesting observation...

The above works perfectly on iOS (and Windows ATE) if the Work Manager 5.3 app is deployed on the SMP platform (version 2.3 SP3 Patch Level 1).

However, if I try the exact same setup of the app deployed on the standalone Agentry Dev Server of the same version (i.e. version 6.1.3.10212) then I get the "Page Error" message inside the HTML control and the External Data property isn't being populated at all...

I double-checked the versions of the standalone Agentry Dev Server and the SMP2.3 Agentry "container" server and they are both 6.1.3.10212 which corresponds to SMP2.3 SP3 Patch Level 1.

In iOS I see this:

And when I examine the object content in Windows ATE, the "External Data" property isn't even set (see the red bubble in the screenshot below):

For the purposes of our implementation here at Hydro Tasmania we will be deploying the app on the SMP platform so it's all good. But it is a discrepancy nonetheless...

Do you think it's possible to log this as a product issue with Agentry Development Server and get the developers to have a look at it? Or is SAP's position that customers should be using the SMP platform instead of standalone Agentry?

Thanks and regards,

Roman.

Former Member
0 Kudos

The Agentry Standalone Server in 6.1 is only for development use.  SMP 2.3 Server is for QA and production.  Please open a ticket under MOB-SYC-SAP or MOB-SYC-OTH.

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

What version of the iOS client are you running on?  There are some known issues with downloading attachments on iOS that you may be running into.  I beleive they were fixed in 6.1.3 PL01 so if you have not updated yet that would be the first step.

--Bill

Former Member
0 Kudos

Hi Bill,

On the iOS side we are running Agentry client 6.1.3.10212

On the server side, we are on SMP 2.3 Service Pack 03 Patch Level 01.

When the SAP Work Manager app is run on SMP, then attachments work perfectly, as stated above.

However, if the SAP Work Manager is run on the standalone Agentry Dev Server 6.1.3.10212 (which is the standalone equivalent of SMP 2.3 Service Pack 03 Patch Level 01) then attachments do not work (i.e. the Agentry Dev server doesn't like External Data property being set to a byte[] array and hence there's no PDF file coming across)

As Steve mentioned, it sounds like a pure Agentry Dev server issue. Would you agree?

Regards,

Roman.

Former Member
0 Kudos

Roman,

Are you starting the Agentry Stand-alone server as a service or are using the GUI?

Stephen

Former Member
0 Kudos

Steve,

Brilliant!! I didn't even think of that. As a test, I killed the "Agentry Dev Server" Windows service in services.msc and then fired up the server through the Agentry Server Admin GUI console. I then blew away the SAP Work Manager on iPad and did a full re-download of the app while the Agentry Dev Server was running via the Admin GUI console.

And viola! The PDF files come up. Which means that the byte[] array worked in Java once I started the Agentry Dev Server through the Admin GUI console.

There must be some funny low-level memory-related stuff going on which behaves differently when the server is started via Admin GUI and when started through Windows services.msc panel.

Go figure!

Thanks for your help,

Roman.

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Roman,

Actually, there is a known issue when running as a service where the Agentry server is not correctly parsing the temp path needed when workign with the java attached files.

The workaround is to run the service under a user account where you have the temp and tmp environment variables set to specific directories (not using %USERPROFILE%) or as you are doing run it directly from your user account (not as a service).  The Engineering team is already working on fix to address it.

Glad you have it working!

--Bill

Former Member
0 Kudos

Thanks Bill and the team!

I think I've got all my answers with regards to questions raised in this discussion thread.

On another note, I've had to raise a separate SCN message thread regarding timezone and localisation issues within Agentry:

http://scn.sap.com/thread/3483252

It has also been raised as a product issue with SAP Market Place (http://service.sap.com/sap/support/message/E/012002523100012656742013)

I realise it's a totally separate thread but was wondering if any of you could take a look at it and get back to me.

In any case, thanks for all the help and support.

Regards,

Roman.

Former Member
0 Kudos

Hi Roman,

We are currently implementing External Data property to show an attachment in HTML field for iOS. May we know what Agentry Plug-in version you are using? We are currently using Agentry_6.0.24.0_EditorPlugin which does not have a "File Location" option for iOS.

Thanks!

mark_pe
Active Contributor
0 Kudos

Matt,

iOS 6 or iOS 7 and what is your version of Agentry? They are different. There are also changes between designed logic between the two especially between Agentry 6.0.26 to 6.0.36.

I can answer this:

  • The external data properties for iOS include Application Support, Documents and iOS Photo Library (guessing the last one is read-only and no idea the difference between the next two).
  • Relative Path is a bit cryptic as there is no help about what this looks like on iOS for any of the above

I'll update this thread as soon as I find my notes on it.

MattHarding
Active Contributor
0 Kudos

Thanks Mark. Answers to your question:

iOS 7 running SMP 2.3 Agentry (SP 2) for SAP Work Manager 5.3 running on the latest iOS client 6.1.3.2001 (or something like that).  e.g. Assume mostly the latest of everything but from a server perspective a month old (so not the SP3 release).

Cheers,

Matt

mark_pe
Active Contributor
0 Kudos

As promise above, I will answer this:

  • The external data properties for iOS include Application Support, Documents and iOS Photo Library (guessing the last one is read-only and no idea the difference between the next two).
  • Relative Path is a bit cryptic as there is no help about what this looks like on iOS

Here are the notes I got from the latest Agentry build 6.0.36 (November 1 2013 release - your version of Agentry should be later than that release to get the same example below - bug# AG-25805).

Example iOS setup 1:

Editor

                  Base Path: Application Support

                  Relative Path: External Data

Resulting path in the app "Library/Application Support/External Data"

Important notes: Users will have to explicitly define "External Data" as  the Relative Path to support

backward compatibility with an existing application that previously was defaulting to "/Application Support/External Data/" (pre-6.0.36), the designer will have to make a change in the editor definitions to set the "Relative Path" setting to the string "External Data". It will no longer default to an "External Data" folder if the base path is "Application Support".

Example iOS setup  2:

Editor

                  Base Path: Application Support

                  Relative Path: Downloaded Docs

Resulting path in the app "Library/Application Support/Downloaded Docs"

Hope this helps.