10 Replies Latest reply on Dec 8, 2016 6:22 AM by Thorsten Fleischmann

    Examples for angular rx-services

    Thorsten Fleischmann
      Share This:

      Hi,

       

      here are some examples for angular services:

       

      Get data page from record:

      var queryParams = {
              propertySelection: "179,7", // ids of fields to get
              queryExpression: "'7'!= 3" //not rejected
          };
      var foo = rxRecordInstanceDataPageResource.withName('<package>:<recordname>');
      foo.get(1000,0,queryParams).then()
      
      

       

      Get user data

      rxSession.getUser()
      

       

       

      Get configuration data

      AdminSettingResource.getComponentSettingData('test').then(function(data) {
           $scope.mode=data.values[0].settingValue;
      });
      

       

      Create a new record instance

      var objectRecord = rxRecordInstanceResource.withName('de.materna.tf.TestTF:Object');
      var createRecord = function () {
        objectRecord.getNew().then(function (record) {
        var fields = record.fieldInstances;
        fields[536870917].value = 0;
        fields[8].value = 'test description';
        return objectRecord.post(record);
          });
      };
      

       

       

      Get a record

      var objectRecord = rxRecordInstanceResource.withName('de.materna.tf.TestTF:Object');
      objectRecord.get('IDxzy').then(
              function(record) {
                  console.log(record.getValue(8));
              }
      );
      

       

      Update a record

      var objectRecord = rxRecordInstanceResource.withName('de.materna.tf.TestTF:Object');
      objectRecord.get('IDxzy').then(
              function(record) {
                  record.setValue(8, 'new description');
                  record.put();
              }
      );
      

       

      Thorsten Fleischmann - added "Get a record" and "Update a record"

        • 1. Re: Examples for angular rx-services
          Dave Sulcer

          We know that the documentation is lacking here and we are beefing it up.

           

          Here is a snippet of code that may help - a big caveat in that I have not gotten this example integrated into working code yet and it may not work at runtime.  I normally don't like to share code that may not work but in this case it may serve to help answer your question.   It is based on the extension point of creating custom "Javascript actions" that show up in Innovation Studio's view designer.

           

          // Module.

           

          (function () {

              'use strict';

           

           

              angular.module('com.example.util-scripts.actions.create-record', [

                  'com.bmc.arsys.rx.standardlib.action',

                  'com.bmc.arsys.rx.standardlib.record.defintion',

                  'com.bmc.arsys.rx.standardlib.record.instance'

              ]);

          })();

           

           

          // Config.

          (function () {

              'use strict';

              angular.module('com.example.util-scripts.actions.create-record').config(function (rxActionProvider) {

                  rxActionProvider.registerAction({

                      name: 'com_example_util_scripts_CreateRecordAction',

                      label: 'Create Record',

                      parameters: [

                          {

                              name: 'recordDefinitionName',

                              label: 'Record Definition'

                          },

                          {

                              name: 'initialStatus',

                              label: 'Initial Status'

                          }

                      ]

                  });

              });

          })();

           

          // Service.

          angular.module('com.example.util-scripts.actions.create-record')

              .service('com_example_util_scripts_CreateRecordAction',

                  function (rxRecordInstanceResource, RX_RECORD_DEFINITION) {

           

                  // recordDefinition in the format my-bundle-id:RecordDefName

           

                  this.execute = function (recordDefinitionName, initialStatus) {

           

           

                      var recordResource = rxRecordInstanceResource.withName(recordDefinitionName),

                          recordInstance = rxRecordInstanceResource.getNew();

                         

                      recordInstance.setValue(RX_RECORD_DEFINITION.coreFieldIds.status, initialStatus);

           

           

                      recordResource.post(recordInstance);

                  };

              });

          })();

          1 of 1 people found this helpful
          • 2. Re: Examples for angular rx-services
            Thorsten Fleischmann

            Thanks!

             

            Meanwhile I also constructed a example for creating a new request - but it is a little bit different.

             

            Do you also have a example for modifying a record? Is there a even service for that or do I have to use the REST-API by now?

            • 3. Re: Examples for angular rx-services
              Thorsten Fleischmann

              It took me some time but I was able to figure it out by myself....

               

              I updated the original post with everything I found (create, get, modify). Hope it helps...

              • 4. Re: Examples for angular rx-services
                Justin Bakker

                I used this to create records:

                 

                RecordService recordService = ServiceLocator.getRecordService();
                RecordInstance recordInstance = recordService.buildRecordInstance("com.acme.myapp:machines");
                
                recordInstance.setFieldValue(536870915, "1"); 
                recordInstance.setFieldValue(8, "2");
                recordInstance.setFieldValue(536870913, "3");
                
                recordService.createRecordInstance(recordInstance);
                
                1 of 1 people found this helpful
                • 5. Re: Examples for angular rx-services
                  Thorsten Fleischmann

                  Thank you! But isn't that java? I was asking for JavaScript/Angular    but java examples are also very welcome

                  • 6. Re: Examples for angular rx-services
                    Justin Bakker

                    Sorry, you're absolutely right. I completely misread. The clue was in the title.

                    • 7. Re: Examples for angular rx-services

                      This is very helpful, but I have a few more questions.

                       

                      In your example you used:

                      queryExpression: "'7'!= 3" //not rejected

                       

                      Can this do string matching?

                      What about GUIDs?

                      What is the equality operator, = or ==?

                       

                      Sorry if this sounds dumb, but when it's 2-3 mins between attempts it gets very difficult to debug.

                      • 8. Re: Examples for angular rx-services
                        Thorsten Fleischmann

                        The query is a regular AR Query. So '7' refers to the field status and 3 is should be "assigned". So this would eventually work too: "'Status' != \"assigned\"'

                         

                        You can also use GUIDs and string matching (LIKE "%"), just as you can do in every ar qualification.

                         

                        What do you mean by 2-3 mins between attempts? If you use grunt you can debug that very quickly.

                        • 9. Re: Examples for angular rx-services

                          Wasn't able to get Grunt Debug going in my environment, even with help from Anand Vidyasagar. I don't have a background in Remedy at all, so I wasn't aware I was using AR Query and don't have any experience with it.

                           

                          Thanks for your samples.

                          • 10. Re: Examples for angular rx-services
                            Thorsten Fleischmann

                            Ah, sorry! A AR Query is basically like a SQL-WHERE clause. You can use "LIKE", "AND", "OR", etc. You can reference fields by ID or by database name. Here you will find some examples:

                            Examples of advanced search bar statements - BMC Remedy Action Request System 9.1 - BMC Documentation