Home Forums Development help with Enumeration conversion on JS nexj framework needed

Viewing 6 reply threads
  • Author
    Posts
    • #10335
      Jack ZhangJack Zhang
      Participant

      background : We are using the NODEJS application to use the model services

      I’m trying to create a new client (class Company) but hitting issues with Enumerations:

      this is the minimum required:

      code example:
      <pre class=”lang:js decode:true”>const clientInfo = JSON.parse(req.body);
      const draft = {
        …clientInfo,
        $class: ‘Company’,
        $event: ‘create’
      };

      obj.update(draft, ‘(lastName hsCMAXCRMId)’, true, genericResponseHandler(res, next, REQ_TYPES.OTHER, null), null, null);
      payload example:
      <pre class=”lang:js decode:true”>{
      “lastName”: “new company name”,
      “hsClientType”: “CMBMME”,
      “hsConsent”: “Denied”,
      “active”: 1
      }

      error:
      <pre class=”lang:java decode:true “>[4/16/19 16:32:52:404 GMT] 0000017c JSONServer E [http:130.50.4.173:59276 nexjsa] Error processing the JSON request (reference id 30ybbl)
      nexj.core.rpc.RequestException: Invalid value in attribute “hsClientType” of class “Company” (expected TransferObject). (err.rpc.objectType)

       

      Obviously, nexj framework did not convert plain text “CMBMME” to the correct type nexj server requires.

      I looked for (proper data format / conversion process) in the dev-guide documentation. I wasn’t really able to find anything useful from there.

      So I seek your expertise on this issue: How do I create new data that has enums as required fields? Does it require a specific data format? Or some kind of special handling? Do I have to do something in the nodeJS code such as:
      <pre class=”lang:js decode:true”>const draft = {
      …clientInfo,
      hsClientType: {
      …clientInfo.hsClientType,
      $class: ‘ClientTypeEnum’
      },
      $class: ‘Company’,
      $event: ‘create’
      };
       

      0
    • #10348
      bFanekbFanek
      Participant

      Hi Jack,

      Yes, as you can see from the model, the hsClientType attribute is non-primitive and you would need to pass an object of type “ClientTypeEnum”. Your RPC call was failing because your payload is passing a primitive string instead. To pass an object for example:
      {
      ‘lastName’: ‘Hello’,
      ‘hsClientType’: {
      $class: ‘ClientTypeEnum’
      ‘value’: ‘CMBMME’
      },
      }

      For any non-primitive objects you can pass the the $class name and its $OID. You could use the read1() function to get the OID of a single specific object based on a where clause.

      I believe Weiguo had already implemented something similar with EntityParticipation and UserParticipation objects (linking a User/Entity to an Act/Interaction). There could be examples your repository. I would refer to the functions implemented in the nexjs.js file.

      Thanks!

      0
    • #10357
      Jack ZhangJack Zhang
      Participant

      Hey Basel,

      we’re trying to create almost 10k rows of record. If each operation does 2 calls to read1(), the performance would be impacted.

      Btw, using your suggestion above results in access denied because we’re trying to create instead of read. I also tried:

      hsClientType: {
      value: ‘CMBMME’,
      $class: ‘HSBCClientTypeEnum’,
      $event: ‘read’
      }

      Error: Unknown member “read” with argument count 1

      I’m wondering if I have options to this other than doing 2 read1() calls for each row of record. Thanks!

      0
    • #10366
      Ed ShawEd Shaw
      Keymaster

      If I do a request over REST for an Enum, I get something like…

      http://localhost:7081/nexj/json/ClientTierEnum?attributes=(value)&$indent

      I think you need to first read and cache the values of the enumeration in your code. Then when posting an update or create, as in the following snippet, use the oid. I believe you need to use the oid and not the value.

      Cheers,

      Ed

      0
    • #10404
      Jack ZhangJack Zhang
      Participant

      Hi Ed,

      Thanks for your response. I tried your approach and it works with minimum client info:
      <pre class=”lang:js decode:true”>{
      “lastName”: “XXXXXXXXX”,
      “hsCIN”: “1000032548”,
      “hsClientType”: “CMB – MME”,
      “hsConsent”: “Denied”,
      “active”: 1
      }

      as a follow up question, I tried to upload client with industry and sector ID both type string in Company.meta:
      <pre class=”lang:js decode:true “>{
      “lastName”: “XXXXXXXXX”,
      “hsCIN”: “1000032548”,
      “hsClientType”: “CMB – MME”,
      “hsConsent”: “Denied”,
      “dlIndustryID”: “63E30A40AC60446CAEDFE303BEFE152C”,
      “dlSectorID”: “038787310D1A4F9EBFE609E6DC9B8CDE”,
      “active”: 1
      }

       

      and got an Invalid Client Error thrown from nodejs nexj framework:

      error: Error: Invalid Client

      Request Body:

      RequestBody: {“$commit”:true,”$lock”:true,”$locale”:””,”$invocations”:[{“$object”:{“lastName”:”XXXXXXXXXXXXX”,”hsCIN”:”1000032548″,”hsClientType”:{“$oid”:”46434D424D4D4542656E4B53434C49454E5454595045″,”$class”:”XXXXClientTypeEnum”},”hsConsent”:{“$oid”:”4644454E49454442656E4E53434F4E53454E54535441545553″,”$class”:”XXXXConsentEnum”},”dlIndustryID”:”63E30A40AC60446CAEDFE303BEFE152C”,”dlSectorID”:”038787310D1A4F9EBFE609E6DC9B8CDE”,”active”:1,”$oid”:”@1″,”$class”:”Company”},”$event”:”create”}],”$filters”:[{“$class”:”Company”,”attributes”:{“$expr”:”(lastName hsCMAXCRMId)”}}]}

      Is there any way to turn on verbose logging so I could know what exactly is wrong with the additional fields I provided? Or do you have any suggestions on approaching this kind of issue?

       

      Regards,

      Jack

      0
    • #10415
      Ed ShawEd Shaw
      Keymaster

      Hmmm, It’s not clear to me where you are getting there error from. Is it being thrown in NODE or is it a result you are getting back from the model server? If it is in the model server, you can crank up the logging levels and see what you are getting there. You can also be very specific about logging only the RPC classes if that is what you are looking for. Otherwise, setting the logger to DUMP will just overwhelm your logs. Look at the logging article in community for more ideas. Here are some articles

      Getting Control of Your Console Logger

      https://documentation.nexj.com/pubdev89/system-administration/monitoring-nexj-applications/enabling-integration-logging/filtering-integration-logs

      Cheers,

      Ed

      0
    • #10447

      Hi Jack,

      Another item to look into is, confirm you are able to create a new record using scheme script and are able to identify the validations for a new record. Example – required attributes etc

      Regards,

      Dhruv

      0
Viewing 6 reply threads
  • You must be logged in to reply to this topic.