12 Replies Latest reply on Jan 15, 2014 8:05 AM by Curtis Gallant

    How to create a functionality same as "save as in developer studio" for form using Java API

    Rajkumar Padole
      Share This:

      I have tried below...

       

      1) I have cloned the existing form, which returened a form object.

      2) set a new name to this cloned object using setName() method, and tried to create new form by passing cloned form object as a parameter to createForm(Form obj) method.

       

      But it gives error which says error while executing getListFields methos.

      Kindly suggest me the way how can we create a copy of form ( Like Save as in dev studio) using Java API.

       

      Thanks in advance.

        • 1. Re: How to create a functionality same as "save as in developer studio" for form using Java API
          Curtis Gallant

          There is much more to a form then just the Form object itself, you also need the Field objects and View object(s) at a minimum I would suspect.

          • 2. Re: How to create a functionality same as "save as in developer studio" for form using Java API
            Rajkumar Padole

            Hi Curtis,

             

            Thanks, Can you please give me an idea how can I use these objects to make exact copy of Form or any idea you can suggest.

             

            Regards,

            Rajkumar Padole.

            • 3. Re: How to create a functionality same as "save as in developer studio" for form using Java API
              LJ LongWing

              Raj,

              Can you copy the code in question?  The way you did it is how I would have tried to do it as well if I would have ever tried to do it (which I haven't)  I imagine that that to truly get a copy, you would as Curtis Gallant points out, also need to add the fields and views to the new form, but you obviously can't add them to a form that doesn't exist, so you would NEED to be able to create the form first before associating fields with it...if you could provide a copy of the code, as well as the actual error being returned, it might help

              • 4. Re: How to create a functionality same as "save as in developer studio" for form using Java API
                Curtis Gallant

                It gets even more complex when you deal with ITSM forms as they are part of applications.  So one cannot just clone the entire object as you need to remove traces of the application licensing from the Properties.  You also won't be able to create the 'copy' until you have created all the fields at a minimum to support elements like the sortInfo, Indexes, Audits and Results lists fields (and the fields need to know what view to be in so you need to create View first).

                • 5. Re: How to create a functionality same as "save as in developer studio" for form using Java API
                  LJ LongWing

                  Curtis, all of the Form Properties would be associated with the form object, so if doing a 'save as', getting the original object, all of those elements would be populated....I've never done this before, so just shooting around in the dark here.

                   

                  You need to have a form before you can associate a field to the form, and I believe that the view is also dependent upon a form...so I think both would require you to create the form, then create the views for the fields to be on, then create the fields to put into those views.  Once you have the fields added to the new form, I would think that you need to update the Results List, Indexes, etc as you indicated because they wouldn't be able to be there on an initial form....maybe you need to do this.

                   

                  1 - Create empty form of proper type (Regular, Dialog, etc)

                  2 - Copy the Views from Form1 to new Form2

                  3 - Copy the Fields from Form1 to Form2

                  4 - Update Form Properties to match those of Form1

                   

                  No clue if this will work, but it makes sense.

                  1 of 1 people found this helpful
                  • 6. Re: How to create a functionality same as "save as in developer studio" for form using Java API
                    Curtis Gallant

                    The general concept you have written I believe is correct however the implementation will be quite complex.  Here is how I see it based on your steps:

                     

                    1 - Create empty form of proper type (Regular, Dialog, etc)

                    - This should work fine, we can set some of the properties already from the original, I wouldn't even use clone here, just use the get methods from the orig form to populate the set methods for some of the various pieces that are not field dependent

                     

                    2 - Copy the Views from Form1 to new Form2

                    - This again should be mostly ok but because our newly created form will already have a default view created, we'll need to delete that original view (or maybe rename it if it's the same VUI as the orig form already)

                     

                    3 - Copy the Fields from Form1 to Form2

                    - This is where there will be some issues.  Copying fields have a ton of annoyances when dealing with big complex forms.  Take HPD:Help Desk as an example.  There are many fields that are in the Reserved range so you can't simply get a List<Field> from the orig form and then try to use the createMultipleField method after switching all their forms to your new target form as they will fail for all the reserved fields (you can only override the reserved field flag with normal createField method unless there is some hidden undocumented way).

                     

                    Assuming you get by this, then there is the issue with field dependencies, e.g. you can't create a column field until the table holder is created, you can't create a panel until the panel holder is created, etc.  So you need to bring in the fields one at a time by type, again, unless there is some undocumented method overload or keyword that brings things in the proper order.  Table fields and Attachment Fields will probably throw other issues at this technique I would suspect.

                     

                    4 - Update Form Properties to match those of Form1

                    -Assuming you set some of the non-field related options already in #1, you can then set the rest here, like audit, index, audit, results list, etc.

                     

                    The above is wayyyy more complex then I'm sure it has to be but I've sifted through the API docs and I can't locate anything that may make the above easier as I'm sure I could hack something up that does all of the above in a couple of hours but it would be very inefficient so I have to believe Dev Studio has a better way it uses to do this.

                    1 of 1 people found this helpful
                    • 7. Re: How to create a functionality same as "save as in developer studio" for form using Java API
                      Curtis Gallant

                      Issue with the reserved fields seems to be able to be bypassed by executing setReservedIDOK(true) on each of the fields.  Still have the issue with sequence though.

                      • 8. Re: How to create a functionality same as "save as in developer studio" for form using Java API
                        Rajkumar Padole

                        Hi LJ and Curtis,

                        Thanks for your help. PSB code and error, kindly give suggestion

                         

                        public Form getOldFormObj(String FornName){
                          
                           try {
                           oldFormobj = user_session.getForm(FornName);
                          
                           } catch (ARException e) {
                           System.out.println(FornName + " does not exist on server.");
                           e.printStackTrace();
                           }
                          
                           return oldFormobj;
                          

                            }

                           

                            public Form createNewForm(){

                           try {
                           newFormobj = (Form) oldFormobj.clone();
                           newFormobj.setName(newFormName);
                           } catch (CloneNotSupportedException e1) {
                           // TODO Auto-generated catch block
                           e1.printStackTrace();
                           }
                           try {
                           user_session.createForm(newFormobj);
                           System.out.println("----------------------------------------------------");
                           System.out.println("Form created successfully");
                           newFormobj = user_session.getForm(newFormName);
                           } catch (ARException e) {
                           System.out.println("Error while creating new form");
                           e.printStackTrace();
                           }
                          
                           return newFormobj;
                          

                            }

                         

                        Error:

                         

                        Error while creating new form

                        ERROR (303): Form does not exist on server;

                            at com.bmc.arsys.apitransport.ApiProxyJRpcBase.verifyStatus(Unknown Source)

                            at com.bmc.arsys.apitransport.ApiProxyJRpcBase.a(Unknown Source)

                            at com.bmc.arsys.apitransport.ApiProxyJRpcBase.arCall(Unknown Source)

                            at com.bmc.arsys.api.ProxyJRpc.ARCreateForm(Unknown Source)

                            at com.bmc.arsys.api.ARServerUser.createForm(Unknown Source)

                            at com.bmc.arsys.api.ARServerUser.createForm(Unknown Source)

                            at com.aif.CreateNewForm.createNewForm(CreateNewForm.java:42)

                            at com.userinterface.GetUserInfo.main(GetUserInfo.java:31)

                        • 9. Re: How to create a functionality same as "save as in developer studio" for form using Java API
                          LJ LongWing

                          Raj,

                          I recommend you look into the 'setKey' function.  Due to the fact that you are getting your form definition from an existing form, the 'key' is the actual 'unique identifier'...so if you utilize both setName and setKey, you may be able to create your form properly.

                          • 10. Re: How to create a functionality same as "save as in developer studio" for form using Java API
                            Curtis Gallant

                            @Raj / @LJ LongWing,

                             

                            I have posted a POC solution on my site here:

                             

                            http://soleauthority.net/replicating-save-as-functionality-of-developer-studio-using-java-api/

                             

                            Please take a look and let me know if you have any questions.  It's actually a lot more complex then one would figure with workarounds required based on the type of form and the types of fields but I got most of it working last night as it tripped my curiosity and I was in the mood to code .  I again would hope there would be a simpler way (using API only, no def file import / export tricks) but I am not aware of one so anybody finds one I would love to see it as it shouldn't need to be done in this roundabout way.

                            • 11. Re: How to create a functionality same as "save as in developer studio" for form using Java API
                              Rajkumar Padole

                              Thanks Curtis, this is really helpful.

                               

                              Yesterday I was trying to achieve it by the ways you and LJ suggested , I got success to create a new form with all fields copied from old form, which was very complex.

                               

                              I will refer your code for further development, it is really helpful.

                              You are really an expert .   Still there are many complex requirement I have .

                               

                              Thanks again for your help.

                               

                              Regards,

                              Raj Padole.

                              • 12. Re: How to create a functionality same as "save as in developer studio" for form using Java API
                                Curtis Gallant

                                You're welcome, good luck with the rest of your requirements