Home › Forums › Development › help with Enumeration conversion on JS nexj framework needed
- This topic has 6 replies, 4 voices, and was last updated 5 years, 8 months ago by Community Manager.
-
AuthorPosts
-
-
April 16, 2019 at 3:48 pm #10335Jack ZhangParticipant
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 -
April 16, 2019 at 3:57 pm #10348bFanekParticipant
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 -
April 16, 2019 at 4:23 pm #10357Jack ZhangParticipant
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 -
April 16, 2019 at 5:23 pm #10366Ed ShawKeymaster
If I do a request over REST for an Enum, I get something like…
http://localhost:7081/nexj/json/ClientTierEnum?attributes=(value)&$indent
JavaScript12345678910111213141516171819202122[{"$class": "ClientTierEnum","$oid": "45544945524142656E4F53434C49454E5454494552454E554D","value": "TIERA"},{"$class": "ClientTierEnum","$oid": "45544945524242656E4F53434C49454E5454494552454E554D","value": "TIERB"},{"$class": "ClientTierEnum","$oid": "45544945524342656E4F53434C49454E5454494552454E554D","value": "TIERC"},{"$class": "ClientTierEnum","$oid": "4A554E41535349474E454442656E4F53434C49454E5454494552454E554D","value": "UNASSIGNED"}]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.
POST example with enum = TIERAJavaScript12345678910{"$class": "Person","$oid": "1021E33F4F02864035ABF7FF9F69862ABF","lastName": "Lamonts","tier": {"$class": "ClientTierEnum","$oid": "45544945524142656E4F53434C49454E5454494552454E554D"},"firstName": "Tim"}Cheers,
Ed
0 -
April 19, 2019 at 2:21 pm #10404Jack ZhangParticipant
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 -
April 23, 2019 at 11:34 am #10415Ed ShawKeymaster
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
Cheers,
Ed
0 -
April 23, 2019 at 11:50 am #10447Community ManagerKeymaster
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
-
-
AuthorPosts
- You must be logged in to reply to this topic.