9 Replies Latest reply on Oct 13, 2011 8:02 PM by yumao NameToUpdate

    Has anyone been able to successfully create a new field on a form using the API?

    Brent Goodman
      Share:|

      I have been successful in creating new Schemas/Forms into the ARSystem, and adding new fields by using the ARSystem API's. The problem I am having is that the fields are not being placed into the default view. I have to manually open the form in the Admin Tool and add my fields to the view. Does anyone know how to get these fields added into the correct view at the time of creation?

       

      All my work is currently in C# with ARSystem 7.1 and CMDB 2.0.1/2.1, using their respective API's. The basic format that I am using goes like the following (number of lines edited down to keep short):

       

      try

       

       

      {

       

       

        CharacterField bgChrField = new CharacterField();

        bgChrField.Name = fieldName;

        bgChrField.FormName = formName;

        bgChrField.Id =

      Convert.ToUInt32(fieldId);

        bgChrField.FieldOption = 2;

       

        bgChrField.CreateMode = 1;

        bgChrField.Limit = bgChrLimit;

        bgChrField.Permissions = bgPermissionList;

        bgChrField.DisplayInstanceList = bgDisplay;

       

        BEG_Ctrl.CreateField(bgChrField);

      }

       

      catch (BMC.ARSystem.ARException ex)

      {

       

        MessageBox.Show(ex.Message, "ARException Occured...");

      }

       

       

      Any suggestions or solutions would be greatly appreciated...

       

       

        • 1. Re: Has anyone been able to successfully create a new field on a form using the API?
          Brent Goodman

          I forgot to mention that when I manually add the fields into the default view and save, I get the following warning from the AdminTool, but the save does complete and I can see everything in the UserTool when loaded:

           

          Field : TestField_1:

          Creation of one of the SQL views for the form failed within the SQL database. Operation completed successfully, but the SQL view is not in place. ARWARN 69).

           

          Field : TestField_2:
          Creation of one of the SQL views for the form failed within the SQL database. Operation completed successfully, but the SQL view is not in place. ARWARN 69).

           

          Field : TestField_3:

          Creation of one of the SQL views for the form failed within the SQL database. Operation completed successfully, but the SQL view is not in place. ARWARN 69).

          • 2. Re: Has anyone been able to successfully create a new field on a form using the API?

            Hello,

            The first think that comes to my mind is that you should take a look at the public void SetVui member function of the Server class.

             

            Best Regards,

            Andrey

            • 3. Re: Has anyone been able to successfully create a new field on a form using the API?

              This is an old post, but thought I would share some details that I came across.

               

              I have been able to successfully add new fields to ARS forms. The project I am working on required us to create 23 staging forms which each contained upwards of 50 fields each. The problem was that the data columns were in a state of change. The solution was to automate the process to create the forms, add the fields based on the file name and the csv column headings. The end result was the staging forms were used to import data into our CMDB.

               

              Most of the API is a learn by trial and error. There is some nice documentation in the Java workd, but not much in the .Net. The easiest way to solve this problem was to take an existing field and pull it apart in the Quick Watch while debugging. Here you can see how the structures are put together and the values that should be used. The field structure is fairly complex and parts change depending on the field type.

               

              The code that you displayed for the creation of a field is missing alot of data structures that need to be added. There are structures within structures that need to be created and populated. The solution that we ended up following due to time constraints was to just have a dummy form with all the field types on it. As we built our new forms, we would take the field type that we wanted and load its structure into memory. We would then make some modifications to the data (name and label changes, position of fields) and then save it to the new form.

               

              The process of coping the field ensured that all the required data fields/structures were in place. Once we started doing this, we no longer got the error messages when we opened the form in the Admin Tool and the field showed up in the default views.

              • 4. Re: Has anyone been able to successfully create a new field on a form using the API?

                i have created a new field with java_api

                field.setName("sss"+sourceForm.getName());

                aRServerUser.createField(field,true);

                • 5. Re: Has anyone been able to successfully create a new field on a form using the API?

                  Do you have the java code to create a field in remedy 7.5 ?

                  • 6. Re: Has anyone been able to successfully create a new field on a form using the API?

                    Hi

                     

                     

                     

                    Create a old form with the name P1 by hand.

                     

                    Create a new form and filed with  JAV AAPI

                     

                    Such as this.

                     

                     

                     

                             private void createFieldOnly(String sourceForm, Field field, int viewid,

                     

                                                int startId, ARServerUser context) throws Exception {

                     

                     

                     

                                       Field temp = field;

                     

                                       int x1 = 0;

                     

                                       int starty = 12 + 2166;

                     

                                       int x11 = 0;

                     

                                       int starty1 = 12 + 2166;

                     

                                       while (x1 < 10) {

                     

                                                temp.setFieldID(startId + x1);

                     

                                                temp.setName("cccc" + x1);

                     

                                                temp.setForm(sourceForm);

                     

                                                DisplayInstanceMap diMap = temp.getDisplayInstance();

                     

                                                // each x 10000 means 100, each y 2166 mean 20

                     

                                                CoordinateInfo coordinateInfo1 = new CoordinateInfo(2800, starty

                     

                                                                   + x1 * 2166);

                     

                                                CoordinateInfo coordinateInfo2 = new CoordinateInfo(32800, starty

                     

                                                                   + 2166 + x1 * 2166);

                     

                                                if (x1 > 5) {

                     

                                                         coordinateInfo1 = new CoordinateInfo(62800, starty1 + x11

                     

                     

                    • 2166);

                     

                                                         coordinateInfo2 = new CoordinateInfo(92800, starty1 + 2166

                     

                                                                            + x11 * 2166);

                     

                                                         x11++;

                     

                                                         starty1 = starty1 + 2166;

                     

                                                }

                     

                                                List();

                     

                                                lx.add(coordinateInfo1);

                     

                                                lx.add(coordinateInfo2);

                     

                                                diMap.setProperty(viewid, new Integer(3), new Value(lx));

                     

                                                if(x1%2==0)

                     

                                                diMap.setProperty(viewid, new Integer(20), new Value(

                     

                                                                   "charactorqwerqwerqwerqwer ccc" + x1));

                     

                                                else

                     

                                                         diMap.setProperty(viewid, new Integer(20), new Value(

                     

                                                                            "11ccc" + x1));

                     

                                                temp.setDisplayInstance(diMap);

                     

                                                context.createField(temp, true);

                     

                                                x1++;

                     

                                                starty = starty + 2166;

                     

                                       }

                     

                             }

                     

                     

                     

                    Good luck

                     

                    yumao

                    • 7. Has anyone been able to successfully create a new field on a form using the API?

                      Thanks chenyumao.

                       

                      Let me be more precise on my requirement.  I need to create a character field on a regular form using java api (remedy 7.5). 

                       

                      In the above code spippet, I didn't understand these lines (

                                 List();   lx.add(coordinateInfo1);  lx.add(coordinateInfo2); ).

                       

                      Could you please clarify those lines ? 

                       

                      Thanks

                      • 9. Re: Has anyone been able to successfully create a new field on a form using the API?

                        It is should be as this

                         

                        List<CoordinateInfo> lx = new ArrayList<CoordinateInfo>();

                         

                        Email system delete the charactors